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.