This shortcode will display the post’s last modified timestamp. By default it will display the timestamp in the date & time format that you specify in your blog settings.
If you wish to change it you can use the format=”” option to display the date and time any way you want. (Examples: May 4, 2010 6:41 pm or 2010/05/04 18:41 etc…)
Visit the php date() function page for information on different formats.
Just insert the following code to the bottom of your functions.php file.
function jason_moddate($atts) { global $post; extract(shortcode_atts(array('format' => get_option("date_format") . " " . get_option("time_format")), $atts)); return date($format, strtotime($post->post_modified)); } add_shortcode('moddate', 'jason_moddate');
Now you can use [moddate] anywhere inside your posts or pages:
This post was last modified on [moddate]
Will get you:
This post was last modified on May 5, 2010 2:08 am
Format Examples:
Display just the date:
[moddate format="Y-M-D"] 2010-May-Wed
Display just the time:
[moddate format="h:i:s a"] 02:08:40 am
Combine them together for a full timestamp:
[moddate format="Y-M-D h:i:s a"] 2010-May-Wed 02:08:40 am
Created on WordPress version 2.9.2
0 Responses to “WordPress Shortcode: Display the post modified time [moddate]”