How To Show Last Modified Date On Blog Post Instead Of Published Date in WordPress

94Shares

Show Last Modified Date On Blog Post
  • Save

If you want to improve your blog, one of the best things that you can do is update your old posts to keep them relevant.

[Tweet “Blog posts are like wine: the older they get, the better they become!”]

But if you’re following best practices and updating your old content, it’s a good idea to tell your visitors that you’ve updated the post so that they know the content is still relevant. This is something I have been using on ShoutMeLoud for the past couple of years and it has been really helpful to our readers. In fact, two years ago, I did a case study on the effects of showing dates on the blog post and also wrote this follow up blog post. You must read these two posts as it is directly linked to your blog SEO and will help you attract more traffic.

Getting back to showing the last updated timestamp instead of last published:

The problem is, WordPress only shows the date when the post was last published, rather than when you most recently updated it, by default.

To fix that issue, I’m going to present a guide on how to show the last modified date on a blog post instead of the published date or the modified date besides the published date.

I’ll show you a few different methods using both code and plugins. While each method is fairly similar, there are some differences between them which I will point out.

How To Show Last Modified Date And Published Date At The Same Time

With this method, you can display the original published date, but automatically add a last modified date as well (but only if you’ve actually modified the post after publishing).

This is a good approach because it shows the age of your post, while also letting readers know that you’ve recently updated it.

To use this method, all you need to do is add a code snippet to your WordPress site.

While you can always add this code snippet directly to the functions.php file in your child theme, I recommend using the free Code Snippets plugin because it makes it easier to keep track of things later on. It also ensures, if you ever switch themes, that your new theme will continue to display the last modified date.

Once you install and activate Code Snippets, go to Snippets → Add New in your WordPress dashboard.

Then, paste this code snippet into the Code box:

function show_last_modified_date( $content ) {
$original_time = get_the_time('U');
$modified_time = get_the_modified_time('U');
if ($modified_time >= $original_time + 86400) {
$updated_time = get_the_modified_time('h:i a');
$updated_day = get_the_modified_time('F jS, Y');
$modified_content .= '<p class="last-modified">This post was most recently updated on '. $updated_day . '</p>';
}
$modified_content .= $content;
return $modified_content;
}
add_filter( 'the_content', 'show_last_modified_date' );

Select the box for Only run on site front-end. Then, click Save Changes and Activate at the bottom:

display-last-modified-date-instead-of-publish-date
  • Save

Here’s what the code does:

  • Checks to see if the post’s last modified date is more recent than its published date.
  • If the last modified date is more recent, it displays a message saying that the post was updated.

You can see an example of this below:

Example of last modified
  • Save

If desired, you can modify the text that displays before the modified date by editing the “This post was most recently updated on” text in the code snippet.

If you’re comfortable with CSS, you can also add your own CSS styling to make the modified date more noticeable.

How To Show Last Modified Date On Blog Post With A Shortcode

If you prefer to avoid the need to use a code snippet, there’s also a free plugin at WordPress.org that makes it easy to display the last modified date of your posts via a shortcode.

The downside of this approach in comparison to the former method is that you have to manually add the shortcode to each post where you want to display the last modified date.

But the benefit is that it is very easy to use.

To get started, install and activate the free Last Modified Timestamp plugin.

Then, add the [last-modified] shortcode to the post where you want to show the last modified date, as well as an optional message before or after the date.

For example, if you input something like this on the backend…

Last modified shortcode example
  • Save

…it will look like this on the frontend of your site:

Last modified shortcode example on frontend
  • Save

How To Show Last Modified Date On All Blog Posts With A Plugin

For another code-free option, there’s a free plugin called Post Updated Date.

Unlike the Last Modified Timestamp plugin from the previous section, there aren’t any shortcodes involved with this plugin.

Instead, as soon as you activate the plugin, it starts functioning.

Here’s what it looks like after you activate the plugin:

Post updated date example
  • Save

The only potential downside of this plugin is that it shows the last updated date no matter what.

The code snippet that I showed you in the first section only appears if you modify the post after its publish date. But with this plugin, the last modified date will still appear even if it’s the same as the publish date.

You can see this in the example below:

Post updated date example
  • Save

For that reason, make sure that you’re ok with this functionality if you decide to use this plugin method over the code snippet I demonstrated earlier.

How To Replace Last Published Date With Last Modified Date

So far, all the methods that I’ve shown you have dealt with showing the last modified date of a post in addition to the original publish date.

But what if you want to completely replace the publish date with the last modified date?

Well, it is possible, but it’s hard to give a tutorial on because you have to edit your theme’s template files directly and every theme handles showing post dates a little differently.

This method is good because it only shows the most recent date to search engines.

But unless you know a little bit about PHP already, I do not recommend trying this method by yourself.

Still want to continue?

If you feel comfortable digging into your theme’s template files and have a recent backup of your site, find the line of code where your theme outputs the publish date and replace it with this:

<?php $u_time = get_the_time('U');
$u_modified_time = get_the_modified_time('U');
if ($u_modified_time >= $u_time + 86400) {
echo "Last updated on ";
the_modified_time('F jS, Y');
echo ", "; }
else {echo "Posted on "; the_time('F jS, Y');} ?>

This code will show:

  • Posted on…[date] for posts that haven’t been updated
  • Last updated on…[date] for posts that you have updated

For example, here’s how that looks when I edited the default Twenty Seventeen theme:

Show Last Modified Date
  • Save

And here’s how it looks on the frontend of my site:

Show Last Modified Date in blog post
  • Save

Again – this is definitely an advanced method. Each theme handles publishing dates differently, so unless you know the basics of PHP, you will struggle to implement this for your own theme by yourself.

Which Method Should You Use On Your Site?

For most bloggers, I think the first method is the best because it is flexible and also fairly easy to implement.

If you want something simpler, both the plugins are solid options, though they aren’t as flexible.

And if you’re comfortable editing your theme’s template files directly, the last method lets you only show a single date, rather than showing both the last published date and the last modified date.

Have you tried any of these methods? Which did you find to be the easiest to implement? Let me know in the comments!

Here are a few hand-picked articles to improve your WordPress Blog SEO:

Was this helpful?

Thanks for your feedback!
  • Save
94Shares
Authored By
A Blogger, Author and a speaker! Harsh Agrawal is recognized as a leader in digital marketing and FinTech space. Fountainhead of ShoutMeLoud, and a Speaker at ASW, Hero Mindmine, Inorbit, IBM, India blockchain summit. Also, an award-winning blogger.

12 thoughts on “How To Show Last Modified Date On Blog Post Instead Of Published Date in WordPress”

  1. Hey Harsh, I have the ready-made code for Astra users. I would love to present it here for your readers. This code is taking the above code by Harsh for reference and is tried and tested on Astra theme only.

    I would love to mention that the above code by Harsh has some limitations like if you use the code given in the above post the author’s name in meta won’t be linking to your author archive. Also if you use the code in the post you won’t be able to use CSS for it to decrease its font size or else out of the box. But the code below works fine for CSS too.

    But the below code will also point to the author archive when you click on the author’s name in meta.

    //Example//

    Before- “September 13, 2020 / By Ajay Choudhury”
    After- “Last Updated on September 13, 2020, By Ajay Choudhury”

    The code is :

    function your_prefix_post_date( $output ) {
    $output = ”;
    $format = apply_filters( ‘astra_post_date_format’, ” );
    $modified_date = esc_html( get_the_modified_date( $format ) );
    $updatetxt = “Last Updated on”;
    $postedtxt = “Posted on”;
    $u_time = get_the_time(‘U’);
    $u_modified_time = get_the_modified_time(‘U’);
    $modified_on = sprintf(
    esc_html( ‘%s’, ‘%s’),
    $modified_date
    );

    if ($u_modified_time >= $u_time + 86400) {
    $output .= ”;
    $output .= ‘ ‘ . $updatetxt . ”;
    $output .= ‘ ‘ . $modified_on . ”;
    $output .= ”;
    return $output;
    }

    else {

    $output .= ”;
    $output .= ‘ ‘ . $postedtxt . ”;
    $output .= ‘ ‘ . $modified_on . ”;
    $output .= ”;
    return $output;
    }
    }
    add_filter( ‘astra_post_date’, ‘your_prefix_post_date’ );
    add_filter( ‘astra_post_meta_separator’, ‘__return_false’ );

    Now for the implementation of the above code just paste it in the functions.php if you are using a child theme. If you are not using a child theme you can use the code snippet plugin and add the above snippet.

    This was just a humble help to all the Astra users. Hope it helps! Well this is the code I myself use on my site.

  2. Sachin Agrawal

    Thanks. I have implemented it thru Code Snippet plug-in. It is showing in the post under the featured image. You could add another article to show how to place this info “last modified date” next to the “publish date).

  3. Jay

    Can you also share how to add Last Updated or Last Modified dates on blogs posted via Shopify?

  4. Jane

    I have used the code snippets plugin and love the simplicity. One thing I want to do though is not having the actual time displayed as it looks like overkill. I also want to prevent it from showing on the homepage but have been unable to find out how to achieve this, any assistance would be most appreciated!

  5. Rohit

    Well explained!
    I will go with implementing your suggested code to my theme because its one-time effort. And Plugins for me is not a good idea as you suggested too many plugins slow down the website. Hahaha 😛

    Thanks.

  6. Martins Toritseju

    This is one of the reason I love wordpress! With a set permalink without year and month of the post (like blogger) and this feature you are sharing. Updating content can be fun and posts will always look fresh. You can even recycle old (updated) posts and pass them off as fresh and your post stay relevant in search engine!

  7. Gaurav Ghosh

    Hello Harsh , I am searching for how to show last modified i found your blog about the article i am searching for . Your Articles Quite Interesting .

    Thanks

  8. Chibuzor Aguwa

    These plugins are indeed useful, especially for some blog posts that require constant updates. I am glad coming across this writeup

  9. Sudipta

    Hi,

    I have tried the first one, it’s very easy to apply.
    But after implement the first method two different date are showing as Last updated- one just bellow the title and another just before start the content.

  10. Bishnu Mahali

    Some themes have pre-enabled this feature in their settings. Thankfully I have one of those themes. However, Thanks for this knowledgeable article.

  11. Arbaz Khan

    I’ve been looking for a good method to implement this and never been able to do it because every guide I referred explained to edit the theme and change the code. But, thanks to you, I will now use the Code Snippets plugin as it seems pretty straightforward and doesn’t need any advanced PHP knowledge.

  12. Liton Biswas

    Hey Harsh,
    Really nice post and well explained.

    It will be helpful for me as I going to update 4 years old posts in one of my blogs.

    Thank you for sharing the post.

    Liton

Leave a Comment

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

Scroll to Top
94 Shares