Archived topic
Last updated date on Google Search
5 replies · Started by Mohammad on May 2, 2019
Hello,
Although on my blog it shows last updated date, on Google search page it shows the publish date. How I can show the last updated date on Google search page.
Here is my blog url.
https://pmstudycircle.com/blog/
Regards,
Hi there,
Ultimately it's up to Google whether to display it or not.
However, some users have reported success by removing the published date from the HTML completely if an updated date exists: https://docs.generatepress.com/article/generate_post_date_output/#only-show-updated-date
Thanks Tom your code worked. Now Google is showing last update date.
Awesome - glad I could help :)
Hi tom, do you want to say that if I'll add this code only then Last updated date will show in the Google search result.
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">%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 );
If yes,
then Please tell me where to add this code and how to add this code?
Waiting for your reply...
Hi there,
yes that code will output the updated date if one exists if not it will return the published date. The code is PHP, this article covers the methods of adding: