How to display last modified date of posts in wordpress

By | November 27, 2015

If you are in the habit of regularly updating your old posts, then might you want to display the last modified date of posts, so indicate how recent or fresh the content in the post is. Your theme might already have the option to display that, but if it doesn’t then doing it is easy, but would need you to mess a little with the code of the theme.

Here is a quick little function that you can add to your functions.php file in the theme (at the end ofcourse).

function add_post_content($content)
{
$date = '<div class="updated_on">Last Updated On : ' . get_the_modified_time(‘jS F Y’) . '</div>';
return $content . $date;
}
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 necessary so that this function is able to do its task before any other plugins get into the way to modify the content.

Download SeoStack

3 thoughts on “How to display last modified date of posts in wordpress

  1. Tony

    I have used this method to modify a meta info on my WordPress blog but it didn’t work.

    Reply
  2. Atul

    I tried this method and my website broke down. I could not get an option to edit my file back afterwards. I had to edit the file back to normal on my server.. It’s not a great guide. If something else was required to be done too, it should have been mentioned.

    Reply
    1. Silver Moon Post author

      Hi Atul
      Thanks for pointing out the error in the code.
      The code was actually being displayed wrong due to html tags.
      I have fixed it now.

      Reply

Leave a Reply

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