Displaying last update / modified date in WordPress posts and pages. If you are running a news or tutorial related blog on WordPress, And your article about the news or tutorial might be updated later. You must show the last modified date, so that your blog readers know if tutorial was updated or not. and for this, Today’s tutorial explains, how to display last update date in WordPress posts and pages.

To display last modified date in your WordPress posts and pages, all you have to do is to add a new function that will display the modified time. WordPress has a function the_time() which displays the published date. To enable modified date function, navigate to the functions.php file of your theme and then add the following code at the bottom :

Also see : How to Schedule Your Posts In WordPress

function md_the_time($format) {

$u_time = get_the_time('U');
$u_modified_time = get_the_modified_time('U');

echo the_time('F jS, Y');

if ($u_modified_time >= $u_time + 86400) {
echo " and last modified on ";
the_modified_time('F jS, Y');
}
}

The function is enabled, now it will display the publish date along with its modified date (if article was modified) as an example, if you have published an article on July 20, 2014 and 5 days later, you come to know that there is an update in the story, You can edit the article. and the function we added, it will show up the update date within its publish date like so “Published on July 20, 2014 and last modified on July 24, 2014.

Now, If you would like to show the hour the article was update, Simply update the new function (above) to following :

function md_the_time($format) {

$u_time = get_the_time('U');
$u_modified_time = get_the_modified_time('U');

echo the_time('F jS, Y');

if ($u_modified_time >= $u_time + 86400) {
echo " and last modified on ";
the_modified_time('F jS, Y');
echo " at ";
the_modified_time();
echo ", ";
}
}

And now, We have to change time functions in the following pages :

  • single.php
  • index.php
  • page.php

So open them up and look for the following function:

the_time()

And replace it with this:

md_the_time()

I hope this tutorial help you to display last modified date in WordPress posts and page. If so, Don’t forget to share this tutorial with your blogger friends. :)