Display last modified date of posts in wordpress

By | August 4, 2012

There is a blue patch at the end of this post that mentions the "Last Updated On" date. It is the date when this particular post of last modified or updated on. Since I keep updating many of the old posts from time to time, thought it would be a nice idea to display the date in the post as well.

Add the following code to the end of functions.php of the the current theme.

function add_post_content($content) 
	return $content . '<div class="updated_on">Last Updated On : ' . get_the_modified_time('jS F Y') .'</div>';
add_filter('the_content', 'add_post_content' , 9);

The function get_the_modified_time gets the modified time of the current post in any given format. The same is added to the post content using the 'add_filter' api function.

The add_filter takes a second parameter called priority. Default is 10, giving anything lesser will mean a higher priority. So we specify 9 to make it higher in priority. Higher priority is needed since many plugins also modify the contents of the post so this function must be able to execute before any other code gets in.

About Silver Moon

A Tech Enthusiast, Blogger, Linux Fan and a Software Developer. Writes about Computer hardware, Linux and Open Source software and coding in Python, Php and Javascript. He can be reached at [email protected].

Leave a Reply

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