Showing a Wordpress post’s ‘last modified’ date
I’ll occasionally return to a post and revise it for improved methodology, test results or whatever. But the ‘posted on’ date always remains the same, even after the post has been updated. I feel that displaying only the ‘posted on’ date could be somewhat confusing, particularly when I state that I’ve updated the post in a comment dated months later. So, in the interest of full disclosure, I have added a few lines of code to the WordPress ’single.php’ template file to supplement each post’s meta data with the date it was last modified. If the post has never been modified or if it was last modified within 24 hours of the ‘posted on’ date, only the ‘posted on’ date is shown.
Of course, this could be used anywhere inside the Wordpress loop, not just in the meta data section. The code I use to show a Wordpress post’s last modified date and time is as follows.
The default Kubrick template’s meta data section:
<p class="postmetadata alt">
<small>
This entry was posted
...
on <?php the_time('l, F jS, Y') ?>
at <?php the_time() ?>
and is filed under <?php the_category(', ') ?>.
You can follow any responses to
this entry through the
<?php comments_rss_link('RSS 2.0'); ?> feed.
The new code, modified to selectively display the last modified date:
<p class="postmetadata alt">
<small>
This entry was posted
...
on <?php the_time('F jS, Y') ?>
at <?php the_time() ?>
<?php $u_time = get_the_time('U');
$u_modified_time = get_the_modified_time('U');
if ($u_modified_time >= $u_time + 86400) {
echo "and last modified on ";
the_modified_time('F jS, Y');
echo " at ";
the_modified_time();
echo ", "; } ?>
and is filed under <?php the_category(', ') ?>.
You can follow any responses to
this entry through the
<?php comments_rss_link('RSS 2.0'); ?> feed.
You can see how this works in the meta data section of this post.
Further customization
I’m using a grace period of 24 hours from the time the post was published, but you could change this by replacing 86400 with however much time you want, specified in seconds.










[...] date” without erasing the “creation date” of the post and I found this great solution from Ardamis.It requires a modification of your WordPress template. The code below was given by Ardamis and [...]
August 21st, 2007
[...] Showing a Wordpress post’s “last modified” date: nothing rocket science, just something that’s a nice idea to implement in your theme. Hey, I just did
Share This [...]
October 30th, 2007
[...] en ardamis.com (con ejemplo para el tema Kubrick que viene por defecto en [...]
October 31st, 2007
[...] Ardamis - Showing a WordPress Posts Last Modified Date [...]
December 24th, 2007
Ardamis, thanks for this code snippet: I really can’t understand why there isn’t such a function built in to WP. You say “If the post has never been modified, only the posted-on date is shown”. It looks like I modify a lot of my posts on the day of publishing e.g. adding “alt” tags, correcting spelling. I’m a perpetual PHP beginner but I’d like to display the following code if modified date > post date by 24 hrs - to allow for such trivial edits (and it makes no sense displaying a post date and modification date that are the same anyway):
<?php /* Last modified */ $u_time = get_the_time('U'); $u_modified_time = get_the_modified_time('U'); if ($u_modified_time != $u_time) { echo "<span class='lastmod'>Last modified "; the_modified_time('F jS, Y'); echo "</span>"; } ?>Is this possible, or am I looking at a plugin to do this?
January 17th, 2008
Wow. Yeah, I should have thought of that when I wrote the code. I’m just the same, always catching a typo or spelling error a moment after publishing a post, so many of my posts have a modified date that is the same as the published date.
I’ve updated the code to allow for a 24-hour grace period after publishing a post, during which any editing won’t show up as a “modification”.
Thanks for the great comment. This blog is better for it.
January 17th, 2008
[...] order to do this, Ardamis has posted a quick code hack to get your single pages to reflect the last modified date. He uses the default Kubrick theme, but [...]
February 8th, 2008
[...] Do you often edits your posts and want your readers to know about it? With this tutorial from Ardamis, you can now display the last modified date of your WordPress posts. [...]
February 10th, 2008
[...] Do you often edits your posts and want your readers to know about it? With this tutorial from Ardamis, you can now display the last modified date of your WordPress posts. [...]
February 15th, 2008
Dude! Great feature! Specially for news sites. Thanks, works like a charm.
April 18th, 2008
[...] order to do this, Ardamis has posted a quick code hack to get your single pages to reflect the last modified date. He uses the default Kubrick theme, but [...]
June 7th, 2008
Thank you so much for this
July 21st, 2008
I do a lot of updating at later times, usually just formatting the modifications in italics, but this is great. Although, now it shows all the times I’ve made grammatical corrections as well.
Do you think this helps the modifications to be picked up by search engines? Sometimes I rewrite 1/3 of the post and would like the revision to be noticed.
August 8th, 2008
[...] via Ardamis’s Blog, there is a great way to only display this information if it has been modified after the original [...]
September 15th, 2008
[...] I found this great little code snipped at ardamis.com [...]
October 6th, 2008
Nice - this really helped me. Do you happen to know why this doesn’t work for pages? It seems that get_the_modified_time() only returns modified time for post, and not pages.
I’d like to show a little “Updated” icon next to the pages that has been changed after a 10 day period, but I can’t figure out how to get the modified time for pages :-/
October 14th, 2008