Skip to content

flatwaterfreepress/wordpress-ap-style-dates

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

Wordpress AP Style Date Filter

What This Plugin Does

This plugin automatically converts WordPress dates to AP Style format across your entire site. According to AP Style rules:

  • Dates appear as "Jan. 25" or "Jan. 25, 2024" (year only if not current year)
  • Months are abbreviated (Jan., Feb., Aug., Sept., Oct., Nov., Dec.) when used with dates
  • Months are spelled out when used alone (March, April, May, June, July)
  • No ordinal indicators (st, nd, rd, th) are used

Installation Steps

  1. Download the ZIP file from Github.
  2. Upload the plugin in your Wordpress instance with the "Upload Plugin" option on your Plugins screen. Access your WordPress installation via FTP, SFTP, or your hosting control panel's file manager
  3. Activate the plugin.

How to Use in Your Templates

Once activated, the plugin automatically converts dates wherever your theme uses standard WordPress date functions. However, you may need to update your theme templates to use the correct functions.

Automatic Conversion

The plugin automatically converts dates displayed by:

  • the_date()
  • the_time() (when displaying dates)
  • get_the_date()
  • get_the_time() (when displaying dates)

Example 1: Basic Date Display

If your theme template currently has:

<?php the_date(); ?>

This will now automatically display as: Jan. 25 (or Jan. 25, 2023 if not the current year)

Example 2: In a Post Loop

Typical article template code:

<article>
	<h2><?php the_title(); ?></h2>
	<p class="post-meta">Published on <?php the_time('F j, Y'); ?></p>
	<?php the_content(); ?>
</article>

After installing the plugin, this will display: Published on Jan. 25, 2024

The format parameter ('F j, Y') is overridden by the plugin, so you don't need to change it.

Example 3: Custom Date Display

If you want to store the date in a variable:

<?php 
$post_date = get_the_date();
echo '<span class="date">' . $post_date . '</span>';
?>

This will output: <span class="date">Jan. 25</span>

Using the Reusable Function

The plugin includes a special function called get_ap_style_date() that you can use anywhere in your theme templates.

What the reusable function does:

  • Allows you to get AP Style formatted dates for ANY timestamp, not just the current post date
  • Useful for custom date fields, event dates, or modified dates
  • Can be used outside of The Loop
  • Doesn't require a post context

Example 4: Display Current Date

<p>Today's date: <?php echo get_ap_style_date(); ?></p>

Output: Today's date: Oct. 24

Example 5: Custom Date Field

If you have a custom field for an event date:

<?php 
$event_timestamp = strtotime(get_post_meta(get_the_ID(), 'event_date', true));
echo 'Event Date: ' . get_ap_style_date($event_timestamp);
?>

Output: Event Date: Dec. 15

Example 6: Last Modified Date

<?php 
$modified_timestamp = strtotime(get_the_modified_date('Y-m-d'));
echo 'Last updated: ' . get_ap_style_date($modified_timestamp);
?>

Output: Last updated: Sept. 30, 2023

Common Template Locations

You may want to check and update these files in your theme:

  • single.php - Individual post template
  • page.php - Individual page template
  • archive.php - Archive listing template
  • content.php or content-*.php - Content template parts
  • index.php - Main blog listing

Look for instances of the_date(), the_time(), get_the_date(), or get_the_time() in these files.

Troubleshooting

Dates aren't changing:

  • Make sure the plugin is activated in WordPress admin
  • Clear your site cache if using a caching plugin
  • Check that your theme is using standard WordPress date functions

Dates show as time (3:45 PM) instead:

  • This is expected if the_time() is being used to display actual times
  • The plugin only converts date formats, not time-only displays

Want to temporarily disable for one instance?

  • You can use the PHP date() function directly: <?php echo date('F j, Y', strtotime(get_the_date('Y-m-d'))); ?>
  • This bypasses the filter

Uninstalling

To remove the plugin:

  1. Deactivate it from PluginsInstalled Plugins
  2. Click Delete on the plugin
  3. Or manually delete the /wp-content/plugins/ap-style-date-filter/ folder

Your dates will return to whatever format your theme specifies.

About

Adds a filter to format WordPress dates in AP Style

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages