How to Display Last Updated Date in GeneratePress Theme?

In this tutorial, we are going to display last updated date in GeneratePress Theme.

In this guide, you’ll learn to

  • Show the last modified date in the WordPress site.
  • Display the last updated date in SERPs.
  • Display published date and last updated date in GeneratePress Theme.
  • Learn to add code in functions.php
  • Learn to use the Code Snippets plugin.
  • And lots more.
How to display last updated date in GeneratePress Theme

Why Last Updated date in GeneratePress?

There are numerous reasons to show the last updated date on your website.

  • To make sure that your readers are getting updated content.
  • To let search engines to show the last modified date in SERPs.
  • Increase the CTR of the blog.

WordPress stores a published date and modified date on the site for every post. If you aren’t using the last modified date code in your blog then whenever you update a post, it will show the published date rather than the updated one.

Date Snippet in SERPs

So, to let your readers are actually getting an updated version of the content, you need to use the last updated date. Also, Google or other search engines show the date in their snippets, so you need to use updated code in your blog. It helps to increase the Click Through Rate (CTR) of your website.

Last Updated Date Snippet in Google SERPs

Display Last Updated Date in GeneratePress Theme

We are going to try two approaches to show the last modified date in the blog posts.

I am using the GeneratePress Premium Theme to implement these methods in my WPLogout blog. You can even try in GeneratePress Free version.

1. Using Plugin

Using a plugin to display the last updated date is the easiest and fastest way in WordPress. And many of us are familiar with the plugin and how to install and activate the plugin.

So, there are various plugins that help to show a modified date in GeneratePress Theme. You can try one of these plugins.

Personally, I haven’t tested the plugin. I always try to avoid the use of plugins in every possible case. so, please test yourself and comment below if it is working for you.

2. Code Snippets in GeneratePress Child Theme

I am using the Code Snippets in functions.php of GeneratePress Theme.

This is a method to implement code in functions.php of the child theme, I am using Code Snippets Plugin in this method. This plugin helps to insert the code in functions.php every time so that you won’t mess up with other snippets in the functions.php.

Moreover, if you want to avoid using Code Snippets plugin then you can create a Child Theme easily with the help of this guide or even can download super basic GeneratePress Child Theme and insert code in functions.php.

Step by Step Process to display last updated date in GeneratePress Theme

I am going to show two codes, you can use any one of them.

Last Updated Date in GeneratePress WordPress Theme
  • Go to Plugins > Add New
  • Search Code Snippets Plugin
  • Install and Activate the Plugin.
  • Go to Snippets in the sidebar > Add New
  • Copy and paste the following code to show the last modified date in the posts.

The following codes help to show the last updated date but the sad thing about this code is that It will show the “Last Updated on” every time also whenever the posts are not updated. But the code works fine.

add_filter( 'generate_post_date_output', function( $output, $time_string ) {
    $time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">%2$s</time>';

    if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
        $time_string = '<time class="entry-date updated-date" datetime="%3$s" itemprop="dateModified">Last Updated on: %4$s</time>';
    }

    $time_string = sprintf( $time_string,
        esc_attr( get_the_date( 'c' ) ),
        esc_html( get_the_date() ),
        esc_attr( get_the_modified_date( 'c' ) ),
        esc_html( get_the_modified_date() )
    );

    return sprintf( '<span class="posted-on">%s</span> ',
        $time_string
    );
}, 10, 2 );

The following code snippet compares date strings – so it should only show updated if there is a day difference. I am personally using this code in my blog. It will show the text “Published on” text if the post is fresh and “Last Updated on” text whenever the post is updated.

Published date in GeneratePress WordPress Theme
add_filter( 'generate_post_date_output', function( $output, $time_string ) {
    $time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">Published on: %2$s</time>';

    if ( get_the_date() !== get_the_modified_date() ) {
        $time_string = '<time class="entry-date updated-date" datetime="%3$s" itemprop="dateModified">Last Updated on: %4$s</time>';
    }

    $time_string = sprintf( $time_string,
        esc_attr( get_the_date( 'c' ) ),
        esc_html( get_the_date() ),
        esc_attr( get_the_modified_date( 'c' ) ),
        esc_html( get_the_modified_date() )
    );

    return sprintf( '<span class="posted-on">%s</span> ',
        $time_string
    );
}, 10, 2 );

Display Published Date and Last Updated Date in GeneratePress

If you are searching to display Published Date and Last Updated date at a time in GeneratePress then you need to use the following code.

  • Go to Code Snippets Plugin.
  • Click on Add New.
  • Enter the Snippet Title.
  • Copy and Paste the following code.
  • Hit Activate Button.
add_filter( 'generate_post_date_output', function( $output, $time_string ) {
    $time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">%2$s</time>';

    if ( get_the_date() !== get_the_modified_date() ) {
        $time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">Published on: %2$s</time> | <time class="entry-date updated-date" datetime="%3$s" itemprop="dateModified">Last Updated on: %4$s</time>';
    }

    $time_string = sprintf( $time_string,
        esc_attr( get_the_date( 'c' ) ),
        esc_html( get_the_date() ),
        esc_attr( get_the_modified_date( 'c' ) ),
        esc_html( get_the_modified_date() )
    );

    return sprintf( '<span class="posted-on">%s</span> ',
        $time_string
    );
}, 10, 2 );

After using the code you will see something like this: published date and last updated in GeneratePress Theme.

Published Date and Last Updated Date in GeneratePress Theme

At the End

After implementing the code or using the plugin to display last updated date in GeneratePress Theme, you can validate a post using Google Structured Data Testing Tool.

The following image is an example that is showing the last Published date and last Modified date in the structured data testing tool.

datePublished and dateModified in Google Structured Data Testing Tool

If you have any problem/feedback, please feel free to comment below.

Share:

GET 100+ FREE SEO TOOLS

Quickly access over 100+ popular SEO/Marketing tools to Boost your website traffic.

Thank you for subscribing. Check your Email(Didn't receive? check Spam Folder)

Something went wrong.

I love things to do with WordPress, Digital Marketing. Blogging has been my Passion. In my free time, I enjoy watching Series and Movies.

2 thoughts on “How to Display Last Updated Date in GeneratePress Theme?”

  1. @Bro that fair and working.

    But it has a problem, If we change the date of post form wp editor so new or reformated post comes in the top in the latest_posts page.

    But if we add this code in function.php and update an article it does not appear in the latest_the page.

    Reply
    • Hi Rushikesh, If you have already posted the article then I advise not to change the date using editor because it’s a bad practice. Use the below code.
      Moreover, you can use the below code in your child theme’s functions.php or use code snippets plugin. Try each method one by one. Something may be wrong at your end.
      I hope it will work at your end.
      Thanks

      Reply

Leave a Comment