WordPress: Last Modified Date

To add a “last modified” date you will need to edit the templates index.php, single.php and page.php – basically the files that might have your post information.

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.

The date your page was published may look a bit like the following:

<?php the_time('l jS F, Y - g:ia') ?>

What you have between the apostrophes will vary depending on how your theme was created. This can be changed using variables found at php.net/date.

The following code will display 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 "; 
	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.