. */ // Set the local time zone based on the WordPress settings $aplocaltime = get_option('gmt_offset'); putenv("TZ=".$aplocaltime); // Post date formatting function ap_date() { $today = get_option('ap_today'); $captoday = get_option('ap_captoday'); $useyear = get_option('ap_useyear'); // Determine the month and set the AP Style abbreviation if (get_the_time('m')=='01') : $apmonth = 'Jan. '; elseif (get_the_time('m')=='02') : $apmonth = 'Feb. '; elseif (get_the_time('m')=='08') : $apmonth = 'Aug. '; elseif (get_the_time('m')=='09') : $apmonth = 'Sept. '; elseif (get_the_time('m')=='10') : $apmonth = 'Oct. '; elseif (get_the_time('m')=='11') : $apmonth = 'Nov. '; elseif (get_the_time('m')=='12') : $apmonth = 'Dec. '; else : $apmonth = (get_the_time('F')); endif; // Determine whether the date is within the current year and set it if (get_the_time('Y')!=date('Y')) : $apyear = ", ".get_the_time('Y'); else : if ($useyear=="true") : $apyear = ", ".get_the_time('Y'); else : $apyear = ""; endif; endif; // Determine whether the date is the current date and set the final output if (get_the_time('F j Y')==date('F j Y')) : if ($today =="true") : if ($captoday == "true") : $apdate = "Today"; else : $apdate = "today"; endif; else : $apdate = $apmonth." ".get_the_time('j')."".$apyear; endif; else : $apdate = $apmonth." ".get_the_time('j')."".$apyear; endif; echo $apdate; } // Post time formatting function ap_time() { $capnoon = get_option('ap_capnoon'); // Format am and pm to AP Style abbreviations if (get_the_time('a')=='am') : $meridian = 'a.m.'; elseif (get_the_time('a')=='pm') : $meridian = 'p.m.'; endif; // Reformat 12:00 and 00:00 to noon and midnight if (get_the_time('H:i')=='00:00') : if ($capnoon == "true") : $aptime = "Midnight"; else : $aptime = "midnight"; endif; elseif (get_the_time('H:i')=='12:00') : if ($capnoon == "true") : $aptime = "Noon"; else : $aptime = "noon"; endif; // Eliminate trailing zeroes from times at the top of the hour and set final output elseif (get_the_time('i')=='00') : $aptime = get_the_time('g')." ".$meridian; else : $aptime = get_the_time('g:i')." ".$meridian; endif; echo $aptime; } // Comment date formatting function ap_comment_date() { $today = get_option('ap_today'); $captoday = get_option('ap_captoday'); $useyear = get_option('ap_useyear'); // Determine the month and set the AP Style abbreviation if (get_comment_time('m')=='01') : $apcmonth = 'Jan. '; elseif (get_comment_time('m')=='02') : $apcmonth = 'Feb. '; elseif (get_comment_time('m')=='08') : $apcmonth = 'Aug. '; elseif (get_comment_time('m')=='09') : $apcmonth = 'Sept. '; elseif (get_comment_time('m')=='10') : $apcmonth = 'Oct. '; elseif (get_comment_time('m')=='11') : $apcmonth = 'Nov. '; elseif (get_comment_time('m')=='12') : $apcmonth = 'Dec. '; else : $apcmonth = (get_comment_time('F')); endif; // Determine whether the date is within the current year if (get_comment_time('Y')!=date('Y')) : $apcyear = ", ".get_comment_time('Y'); else : if ($useyear=="true") : $apcyear = ", ".get_comment_time('Y'); else : $apcyear = ""; endif; endif; // Determine whether the date is the current date and set the final output if (get_comment_time('F j Y')==date('F j Y')) : if ($today == "true") : if ($captoday == "true") : $apcdate = "Today"; else : $apcdate = "today"; endif; else : $apcdate = $apcmonth." ".get_comment_time('j')."".$apcyear; endif; else : $apcdate = $apcmonth." ".get_comment_time('j')."".$apcyear; endif; echo $apcdate; } // Comment time formatting function ap_comment_time() { $capnoon = get_option('ap_capnoon'); // Format am and pm to AP Style abbreviations if (get_comment_time('a')=='am') : $cmeridian = 'a.m.'; elseif (get_comment_time('a')=='pm') : $cmeridian = 'p.m.'; endif; // Reformat 12:00 and 00:00 to noon and midnight if (get_comment_time('H:i')=='00:00') : if ($capnoon == "true") : $apctime = "Midnight"; else : $apctime = "midnight"; endif; elseif (get_comment_time('H:i')=='12:00') : if ($capnoon == "true") : $apctime = "Noon"; else : $apctime = "noon"; endif; // Eliminate trailing zeroes from times at the top of the hour and set final output elseif (get_comment_time('i')=='00') : $apctime = get_comment_time('g')." ".$cmeridian; else : $apctime = get_comment_time('g:i')." ".$cmeridian; endif; echo ($apctime); } // Modified date formatting function ap_modified_date() { $today = get_option('ap_today'); $captoday = get_option('ap_captoday'); $useyear = get_option('ap_useyear'); // Determine the month and set the AP Style abbreviation if (get_the_modified_date('m')=='01') : $apmodmonth = 'Jan. '; elseif (get_the_modified_date('m')=='02') : $apmodmonth = 'Feb. '; elseif (get_the_modified_date('m')=='08') : $apmodmonth = 'Aug. '; elseif (get_the_modified_date('m')=='09') : $apmodmonth = 'Sept. '; elseif (get_the_modified_date('m')=='10') : $apmodmonth = 'Oct. '; elseif (get_the_modified_date('m')=='11') : $apmodmonth = 'Nov. '; elseif (get_the_modified_date('m')=='12') : $apmodmonth = 'Dec. '; else : $apmodmonth = (get_the_modified_date('F')); endif; // Determine whether the date is within the current year if (get_the_modified_time('Y')!=date('Y')) : $apmodyear = ", ".get_the_modified_time('Y'); else : if ($useyear=="true") : $apmodyear = ", ".get_the_modified_time('Y'); else : $apmodyear = ""; endif; endif; // Determine whether the date is the current date and set the final output if (get_the_modified_date('F j Y')==date('F j Y')) : if ($today == "true") : if ($captoday == "true") : $apmoddate = "Today"; else : $apmoddate = "today"; endif; else : $apmoddate = $apmodmonth." ".get_the_modified_date('j')."".$apmodyear; endif; else : $apmoddate = $apmodmonth." ".get_the_modified_date('j')."".$apmodyear; endif; echo $apmoddate; } // Modified time formatting function ap_modified_time() { $capnoon = get_option('ap_capnoon'); // Format am and pm to AP Style abbreviations if (get_the_modified_time('a')=='am') : $modmeridian = 'a.m.'; elseif (get_the_modified_time('a')=='pm') : $modmeridian = 'p.m.'; endif; // Reformat 12:00 and 00:00 to noon and midnight if (get_the_modified_time('H:i')=='00:00') : if ($capnoon == "true") : $apmodtime = "Midnight"; else : $apmodtime = "midnight"; endif; elseif (get_the_modified_time('H:i')=='12:00') : if ($capnoon == "true") : $apmodtime = "Noon"; else : $apmodtime = "noon"; endif; // Eliminate trailing zeroes from times at the top of the hour and set final output elseif (get_the_modified_time('i')=='00') : $apmodtime = get_the_modified_time('g')." ".$modmeridian; else : $apmodtime = get_the_modified_time('g:i')." ".$modmeridian; endif; echo ($apmodtime); } // Set up plugin options function set_apstyle_options() { add_option('ap_today','true','Use today'); add_option('ap_captoday','false','Capitalize today'); add_option('ap_capnoon','false','Capitalize noon and midnight'); add_option('ap_useyear','false','Use the current year'); } function unset_apstyle_options() { delete_option('ap_today'); delete_option('ap_captoday'); delete_option('ap_capnoon'); delete_option('ap_useyear'); } register_activation_hook(__FILE__,'set_apstyle_options'); register_deactivation_hook(__FILE__,'unset_apstyle_options'); // Build options page function admin_apstyle_options(){ // Get the url for options page images $apimgurl = get_bloginfo ( 'wpurl' ) . '/wp-content/plugins/' . basename(dirname(__FILE__)) . '/apdt_icon.png'; $donateimgurl = get_bloginfo ( 'wpurl' ) . '/wp-content/plugins/' . basename(dirname(__FILE__)) . '/donate.gif'; // Start the page and build the sidebar ?>

AP Style Dates and Times plugin options

Plugin information

Plugin options

How to use it

Plugin homepage
If you have questions, comments or improvements, feel free to post them at the plugin page.

 

Support the plugin

Rate it at WordPress.org

Donate
This plugin is free and released under a GNU General Public License, but if you found it useful or it rocks your car, feel free to donate to my booze fund.

Donate

 

Get a stylebook

This plugin is not affiliated with the Associated Press, but no plugin can replace having your hands on the real thing!

Options saved.

Failed to save options. Please try again.

This plugin changes the format of the dates and times of your posts and comments to match Associated Press Style. This is perfect for news and magazine sites running WordPress and for those blog writers with a penchant for style consistency.

What it does

• Adds periods to “am” and “pm” so they become “a.m.” and “p.m.”
• Removes extraneous zeros when the time is at the top of the hour. “1:00 p.m.” becomes “1 p.m.”
• Changes “12:00 a.m.” to “midnight” and “12:00 p.m.” to “noon.”
• Correctly abbreviates months in the date to match AP Style rules. Those are: “Jan.” “Feb.” “March” “April” “May” “June” “July” “Aug.” “Sept.” “Oct.” “Nov.” “Dec.”

 

Options

Use ‘today’ when the post date is the current date

Though technically not an AP Style rule, many publications use the word “today” when it’s the current date.

/>
/>

If you’re using ‘today’, would you like it capitalized?

Depending on where you place the date in your template, you may want the word capitalized.

/>
/>

Display the year in the date if it matches the current year?

According to AP Style, when using a date that is within the current year, the actual year is not needed in the date. However, you may want to include it in the interest of clarity.

/>
/>

Capitalize ‘noon’ and ‘midnight’ when printing the time?

Depending on where you place the time in you template, you may want the words capitalized.

/>
/>



 

Usage

To use this plugin, you have to edit your template files, replacing WordPress’ default date and time tags with the new ones listed below. You can use it on dates and times for posts, comments and post modified information.

For post dates and times

<?php ap_time(); ?> will print the post’s time in AP Style.

Find the <?php the_time(); ?> tag in your template files (single.php, index.php, search.php, archives.php, page.php, etc.) and replace it with:

<?php if (function_exists('ap_time')) { ap_time(); } else { the_time(); } ?>

Using the if statement will make sure the date is still printed if the plugin is deactivated.

Likewise, <?php ap_date(); ?> will print the post’s date in AP Style.

Find the <?php the_date(); ?> tag in your template files and replace it with:

<?php if (function_exists('ap_date')) { ap_date(); } else { the_date(); } ?>

Here’s how I use it:

I put the time before the date, so my code looks like this:

<?php if (function_exists('ap_time')) { ap_time(); } else { the_time(); } ?> <?php if (function_exists('ap_date')) { ap_date(); } else { the_date(); } ?>

That prints something like 1:15 p.m. Sept. 23, 2008 or noon Sept. 23, depending on the option settings.

For comment dates and times

<?php ap_comment_time(); ?> will print the comment times in AP Style.

Find the <?php comment_time(); ?> tag in your comments template file (comments.php) and replace it with:

<?php if (function_exists('ap_comment_time')) { ap_comment_time(); } else { comment_time(); } ?>

<?php ap_comment_date(); ?> will print the comment dates in AP Style.

Find the <?php comment_date(); ?> tag in your comments template file and replace it with:

<?php if (function_exists('ap_comment_date')) { ap_comment_date(); } else { comment_date(); } ?>

For modified dates and times

<?php ap_modified_time(); ?> will print the post’s modified time in AP Style.

Find the <?php the_modified_time(); ?> tag in your template files (single.php, index.php, search.php, archives.php, page.php, etc.) and replace it with:

<?php if (function_exists('ap_modified_time')) { ap_modified_time(); } else { the_modified_time(); } ?>

<?php ap_modified_date(); ?> will print the post’s modified date in AP Style.

Find the <?php the_modified_date(); ?> tag in your template files and replace it with:

<?php if (function_exists('ap_modified_date')) { ap_modified_date(); } else { the_modified_date(); } ?>