How to properly show last updated date in For SEO?

Hi, guys, I have been spending many hours updating old stuff.

I updated a few of my blogpost from 2018 > 2020.

Not just date but I also tried to make it evergreen. For example, my old post was 500 words long but I reformat the content length is now more 1800+ words.

But after editing the content I just change the date and make updates.

But here’s the game - In SERP the date will be changed, and it is good at a point of visitors.

But What what about SEO and search bot?

I mean when I checked the structure data. The last modified and updated dates are the same. (I know it need to add code, I added below code bust still not working)
Screenshot_17

But when I check the structure date of another blog both dates are different.
Check below example of Moz
Screenshot_18

And do you know the funniest part, these sites do not care about SERP but they focus on structure date in order google can understand both dates.
Screenshot_19

Somewhere I learned content age is also matters. So I think by reading dateModified and datePublished Google understands, how content is old?

So for this requirement, I googled and found the following code to generatepress theme. Unfortunately, it not working for me.

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 );

Please, Guys, give me solution and also do research and implement yourself, Not sure but maybe it a ranking factor.

2 Likes

If you are using GeneratePress Theme then the above code should work for any updated posts to show last update date. The same code is working at my end.

Can you elaborate what you did with the code?
Where you paste the code?

Will further assist with the code.

Thanks

1 Like

Can you share a screenshot of the google structure data of any of your updated post?
Like this

I didn’t do anything with code. I just copied and pasted in the child themes function.php file.

1 Like

Ok the code is working for me. Thanks

1 Like

Great to here.

1 Like