How to Add “Last Updated” Date in WordPress 1

How to Add “Last Updated” Date in WordPress

If you’re a blogger, online news publisher, or any other type of article-based website, it’s important to let your visitors know that the articles you’re publishing are new and up-to-date. While WordPress doesn’t come with this feature out of the box, there is an easy way to add the “last updated” date to your WordPress posts.

Today, We will share some simple steps that will allow you to view the date your article was last updated. and make things easier for your website visitors:

When Should You Add Last Updated Date to Your WordPress Posts?

It’s common for most WordPress themes to display the published date of each article, and this works for most websites as well. However, some websites post regularly updated content for a reason.

For example, in the case of a news site, there is a good chance that an old story will need to be updated at some point. This, by the way, i.e. after the article has been posted, could be an update with the latest information on the latest developments on the topic at hand. There are also various online tutorials, product and service reviews, tour guide articles, etc. may all contain time-sensitive information. The relevance and timeliness of such content, pricing, changes in product features, terms of use, etc. may depend on different factors such as Therefore, they need to be updated regularly. If you want your users to be aware of these updates, it can be a good practice to show the last update date in your posts.

Also, for many users, articles older than two years will often be rejected as they are no longer relevant, even if they somehow appear at the top of Google search results.

The thing is, The older your post is, the less chance it has to be clicked.. Google also takes this factor into account when it comes to its ranking algorithm, and also displays the date a post was published (or updated) in the SERPs.

Release date

However, there are articles written years ago with evergreen content that are still relevant today. Still, many websites make sure to update such articles regularly so as not to waste the potential these articles have. this way, they tell users that the content they are interested in is still new. If you’re among those who want to prevent their high-quality posts from losing much-needed views (and frankly, why not?) we recommend doing the same.

While WordPress doesn’t come with the option to display your post’s last modified date by default, fortunately, there’s always the option to do it manually. all you have to do add a few lines of code to the files of the WordPress theme you are using – and this time we’ll show you how.

Without further ado, here are some easy instructions you can follow to display the “Last Updated” date in WordPress. You can achieve this like this: Editing the theme’s functions.php file or add a code snippet to one of your theme’s template files.

Viewing Last Updated Date Using Functions.php

You need to add a line of code inside your theme to include the last updated date before your content. functions.php file.

go Appearance >> Theme Editor in your admin control panel and find your functions.php file. Theme Files list.

Theme Functions

Then add the following code at the very end of the file:

function my_last_updated_date( $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 entry-meta">Last updated on '. $updated_date . ' at '. $updated_time .'</p>';
}
$custom_content .= $content;
return $custom_content;
}
add_filter( 'the_content', 'my_last_updated_date' );

works by code check if there is a difference between the published date of that post and the last modified date. If these two dates are different, the last modified date will be displayed.

Theme Functions Code

After entering your code, be sure to press the key. Update File button.

If you want, you can even add some custom CSS to your theme’s style sheet (or by going to: Appearance >> Customize and using Additional CSS choice). For example, you can use this code as your base:

.last-updated {
font-size: small;
text-transform: uppercase;
background-color: #fffdd4;
}

Here is what our final result looks like:

Last Update Date

Viewing the Last Updated Date Using Theme Templates

Another way to do this is use your theme’s specific template file. Most themes use single.php, index.php, archive.php, etc. to display posts. It uses different templates such as

All you have to do is find the code that shows your date and time in the file and then either replace the existing code with the code we will share with you below or add it just below the “date and time” of the theme. code. The former displays only the last modified date of your post (without the original post date), while the latter displays both dates above your content.

For this purpose, we used the Twenty Seventeen theme. The date and time code of this theme, template-tags.php file.

What we did was find the function named ‘twentyseventeen_time_link’ and place the following just below the ‘get_the_time’ line of code:

$u_time = get_the_time('U'); 
$u_modified_time = get_the_modified_time('U'); 
if ($u_modified_time >= $u_time + 86400) { 
echo "<p class="last-updated entry-meta">Last modified on "; 
the_modified_time('F jS, Y'); 
echo " at "; 
the_modified_time(); 
echo "</p> "; }

You can also use the same code in your theme’s template file.

Viewing the Last Updated Date Using Theme Templates

just shoot Update File button and that’s it – your post will now show the date your post was last modified.

And on our side it looks like this:

Last Modified Date

Collection

If you are a website or blog owner that tries to update their content regularly, you may want to consider adding the “Last Updated” feature to your WordPress posts. This app is particularly useful as it allows you to show your visitors that your content is always up to date and relevant. As you can see from our tutorial, the method that lets you add the code directly to your theme’s functions.php file is relatively simple even for beginners and does the job pretty well. Alternatively, you can easily view the last modified date of your post by adding the code to one of your theme’s template files.

Support our work ❤️

If you enjoyed this article, consider leaving a tip to help us keep publishing great content.

Secure payment on PayPal
Moyens I/O Staff is a team of expert writers passionate about technology, innovation, and digital trends. With strong expertise in AI, mobile apps, gaming, and digital culture, we produce accurate, verified, and valuable content. Our mission: to provide reliable and clear information to help you navigate the ever-evolving digital world. Discover what our readers say on Trustpilot.