Displaying the last updated date & time in WordPress 

Products mentioned
Keep it current

If you have a site with posts that are frequently updated, then it behooves you to let your visitors know the articles they’re reading are current. By default, WordPress just displays the date and time when the post was created.

However, you can make a dozen updates to an article, it will still only show the original date and time.

Some sites offer content  their readers revisit, and from time to time and it makes them feel warm and fuzzy if they see your content is current. If you have updated a post recently, and only the original post date and time is displayed, you might lose visitors because they think a post is old and outdated.

No one wants to lose visitors for something so silly, right?

That sounds groovy. But how do I accomplish this?

I’m glad you asked. This task requires a little coding, but nothing too scary. As of writing this article, there are no plugins available to do this for you, so you’ll have to roll up your sleeves and do a very small amount of coding.

Don’t worry though, I’ll show you the ways of the force.

How to display the last updated date & time in WordPress

First thing’s first… before editing code, always back up your site first! Get into this habit now, less ye be in for it later. Also, be sure you’re editing your child theme, not the parent theme.

Now, with that out of the way, what you’ll want to do is you’ll want to connect to your site via File Manager or FTP. Either works fine.

Next, you will want to navigate to the functions.php file. This is located in your theme. Navigate to public_html > wp-content > themes > twentytwentytwo > functions.php. Now open this file.

*Note: I just happen to be using twentytwentytwo. Your theme will likely differ.

Scroll down to the last line in the functions.php file and hit a hard return. Now enter this code on the new line:

// Last Updated Date and Time

function last_date_updated( $content ) {

$u_time = get_the_time('U'); 

$u_modified_time = get_the_modified_time('U'); 

if ($u_modified_time >= $u_time + 86400) { 

$updated_date = get_the_modified_time('F jS, Y');

$updated_time = get_the_modified_time('h:i a'); 

$custom_content .= '<p class="last-updated">Recently updated on '. $updated_date . ' at '. $updated_time .'</p>'; 

} 

 $custom_content .= $content;

 return $custom_content;

}

add_filter( 'the_content', 'last_date_updated' );

Subsequently, you can also style your new code by going to Appearance > Customize. Then select Additional CSS. Once you’ve entered your custom style, be sure to select the Publish button, at the top.

Enter in this style and modify it as you see fit:

.last-updated {

font-size: small;

color: #ff0000;

text-transform: uppercase;

background-color: #ffff00;

}

Here is an example of what it could look like for you:

Now every time you update a post, it will be reflected on the front of the site. Again, modify the style declaration as you see fit, to better match your theme’s style.

Closing thoughts

It is always a good idea to keep your content fresh, as it will keep  visitors coming back, knowing they are getting the most recent content. There are, of course, many different ways you can edit the code above. This is but one example.

Now go out there and have fun! See you next time.