How to display the Last Updated Date of your posts in Wordpress

How to display the Last Updated Date of your posts in WordPress

Updating your wordpress posts on regular basis is good, both in terms of SEO and the engagement of your readers with your blog. It’s not always true that whenever you publish any article, its complete one in terms of knowledge, depth and worth. As you keep on learning, you come to know new things; which you want to add in your old article.

But when you edit your old post, wordpress by default will not show the last updated date on your articles. Rather, you will see the original published timestamp only. So, here we will show you that how you can show the modified date to your readers instead of published date.

First of all, let’s understand that why you should update your articles.

Why to update posts in wordpress

• Google does not like the old outdated content. Suppose you have written an article on “Best cars to drive”. Then you might want to change its content at some point of time because it is obvious that new cars will come in market in the coming months and those might not have been in your list. So you need to add them so that the content looks evergreen and fresh. Same is been liked by Google.

• As I gave the example above, readers also like the same thing. Who wants to see the outdated data? If anyone wants to purchase the car, why the hell he will spend money on a car that was best 10 years ago and now, it’s not worth?

So considering the above 2 reasons, you should update your old articles. But question is why to show the updated time to users?

Why to show last updated date or timestamp

Let’s see that why we should edit our old wordpress posts.
• Showing the updated timestamp adds plus to an article in terms of SEO. And since everyone wants his/her editorials to rank well in google, so showing the modified date is must.

• If you are altering the content and adding the new date then your blog’s readers will take it as a sign of freshness and will be more interested in reading that stuff.

Now, when we have seen that it’s a good practice to show the last modified timestamp on your blog then let’s see that how to tweak your theme to let it happen.

How to show Last Updated Date in wordpress

Here we are showing you multiple ways so that you can see the date when you edit your article.

Method A – Showing Recently Modified time by adding custom php code in functions.php

1. Go to Appearance –> Themes –> Editor and open functions.php file.

2. Go to the bottom of php file and paste below code.

function bp_last_updated_date( $content ) {
$bp_published_time = get_the_time('U');
$bp_modified_time = get_the_modified_time('U');
if ($bp_modified_time >= $bp_published_time + 86400) {
$bp_updated_date = get_the_modified_time('F jS, Y');
$bp_updated_time = get_the_modified_time('h:i a');
$custom_content .= '

This article was modified on '. $bp_updated_date . ' at '. $bp_updated_time .'

$custom_content .= $content;
return $custom_content;
add_filter( 'the_content', 'bp_last_updated_date' );

3. Save the file.

4. If you want, you can add some css also.
last updated date

This code checks that if the original publishing date is recent than the date on which post was edited. And if it is, then it shows the message as “This article was modified on so and so time”.

Method B – Updating theme’s single.php file to show Published and Modified dates both

Few wordpress themes display the date-time directly in their individual files such as single.php. So adding custom code in functions.php file from method A might not work here. And in such a case, we can follow this new method.

1. Open single.php file.

2. Check the place where you are showing the post-published date. In your browser, you can go to Inspect and can check the code.
last modified date wordpress

3. Add below code at that place in single.php.

$bp_published_time = get_the_time('U'); 
$bp_modified_time = get_the_modified_time('U'); 
if ($bp_modified_time >= $bp_published_time + 86400) { 
<span class="meta-date">
Last updated on ; 
the_modified_time('F jS, Y'); 
 at ; 
 </span> ; } 

4. You can see the code functional as shown in below image. Please note that this method is displaying both timestamps.
recent updated time

Method C – Updating theme’s single.php file to show only Modified time

In above method B, we have added some lines of code in single.php but it displays both dates on the articles. What if you do not want to show the original date at all? Then this current method should work for you.

1. Go to single.php and search for below code-snippet.
modified time wordpress

2. In the above pic, you can see the highlighted code the_time. Change that to the_modified_time; so now your code becomes as shown below:

<span class="meta-date">on the_modified_time(get_option('date_format')); </span>

Please note that the class can vary as per the theme that you are using.

Method D – Using wordpress plugin

There is wordpress plugin too that does the work for you. The developer Evan mattson has developed a wordpress plugin Last Modified Timestamp. After activating the plugin, you will be able to use it. But the downside of this plugin is that on each and every post/page where you want to show the modified date, you have to manually add the below shortcode on that post or page.


See an example in below pic:
last modified timestamp

If you feel lazy adding the shortcode manually to every article then wordpress has given another plugin PostUpdatedDate. Just install it and you can check your articles to see if it’s working fine.

Let us know if you have used the plugin approach or custom code.

Leave a Comment

%d bloggers like this: