Archived topic
Not showing Last Update Date in google search page
5 replies · Started by John on October 4, 2019
Hello
I am using Last update date for my posts. It works well in my site.
but in google search page still showing publish date.
Please help me to show the update date in search result.
Thanks
Hi there,
By default both the published date and updated date are in the markup - Google decides what to read.
You can try only showing the updated date in the markup using this PHP snippet:
https://docs.generatepress.com/article/generate_post_date_output/#only-show-updated-date
Adding PHP: https://docs.generatepress.com/article/adding-php/
Applied below codes. But still showing published date in google structured data testing tool.
Could you check, please?
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: %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 );
How are you adding the code?
By Code Snippets plugin.
Check this screenshot - https://prnt.sc/pexb46
Hi there,
the snippet worked and the date that GP outputs is now only displaying the Updated Date.
Google may be picking up the dates from the head meta tags your SEO plugin is adding. Or it may just be its algorithms dictate the published date as more relevant. Generally, given time and re-crawls, it will pick up the date that is displayed on the page. But we can't control that.