When you are publishing WordPress posts and pages, sometimes you might want to include the date it was last modified as well. This is particularly useful for any pages you have such as those for competitions, or those with content that visitors expect to be updated regularly. WordPress only shows the date you published the post.
You will need to edit the pages index.php, single.php and page.php – these are basically the files that have your template in them.
Choose where you want to display the ‘Last Modified’ date. This could be under your current date or even at the bottom of your page. You need to recognise your own template.
In your coding, the date your page was published will look like the following (you can place the ‘last modified’ date under this, if you wish):
<?php the_time('l jS F, Y - g:ia') ?>
What you have between the apostrophes (I have “l jS F, Y – g:ia”) will vary depending on how your theme was created. This can be changed using variables found at php.net/date.
Now, the following code is what you use to show the ‘last modified’ date.
<?php $u_time = get_the_time('U');
$u_modified_time = get_the_modified_time('U');
if ($u_modified_time >= $u_time + 0) {
echo "Last modified on ";
the_modified_time('l jS F, Y');
echo " at ";
the_modified_time('g:ia');
echo ". "; } ?>
The parts in bold are the variables that display the actual date and time of modification, and as mentioned above, can be found at php.net/date. Keep them within the apostrophes if you edit them.
The parts in italics are the parts that display the text surrounding the date and time. Keep them within the apostrophes if you edit them.
Underlined is a value of time in seconds. This is set to zero so that the modified date will always display, but if you want it to display after a certain amount of time, put that amount of time in seconds (eg. 3600 for an hour).
The date would display like:
Last modified on Sunday 10th January, 2010 at 1:26 pm.
Thank you Ardamis!

Subscribe to Heartdrops