WordPress – Add Last Modified Date to all Blog Posts

Many times after a post is published, comments are received, or new events occur and the original post needs to be updated. WordPress should have a setting allowing it to show the last modified date and/or time for each post.

I wasn’t able to find a setting, but I was able to find some code, link to original code below, to insert into the index.php and single.php files for the theme.  I put the code after the content is displayed. The code shows a small dynamic line at the end of each post with the original posting date and then the last updated date if is greater than 24 hours from the original posting date. 

It displays as follows:  This entry was posted on August 13th, 2009 at 4:23 pm and last updated on August 18th, 2009 at 12:57 pm

The code which needs to be added to the relative files, index.php and single.php for the theme I’m using, is as follows:

<p><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 updated on “;
the_modified_time(‘F jS, Y’);
echo ” at “;
the_modified_time(); } ?>
</small></p>

Showing a WordPress post’s ‘last modified’ date

Leave a Reply

Your email address will not be published. Required fields are marked *

*