Archived topic
Google search results updated date
9 replies · Started by kiant123 on August 24, 2021
Hi,
I see that in google search results my posts are showing the 'last updated date' as the publish date. How do I change it so that the last updated date reflects the true last updated date?
Also I see that the 'updated by' is not the real author nor any author in my users. It seems to have taken a bit of random text from the page. Ideally I'd prefer to not show any 'updated by'.
How would I go about making these changes?
Thanks in advance
Hi there,
Thats Google grabbing the meta from the YouTube video on that page.
Its not Theme related. I provide the recommended fix for that here:
But as you can see from the OPs replies, it may not do what you expect.
Hi David,
That's really interesting to read (if not annoying).
I see it's happening on a lot of pages on my site so I don't think it's feasible for me to put that code in all my posts videos.
One of the recommendations on the google help you linked to in the old thread mentions:
I would recommend you add a date on the page and mark it up with structured data properties, so that google will know when was last page updated.
Is there a way I can do this in generate press or perhaps get it to trigger the updated date in the search results?
You can simply enable the Post Date in Customizer > Layout > Blog --> Posts.
And theres a PHP Snippet for making it display only the Updated Date ( if it exists or it will show the published ):
https://docs.generatepress.com/article/generate_post_date_show_updated_only/
You already have an (SEO ?) Plugin thats adding JSON-LD ( Structured data ) containing the published and updated date on your site. Which SERPs should pull in.
Whether Google chooses to display the date etc is up to them...
That worked well thank you.
How would I add some text before that date so the word Updated: comes before the date. So it may look like:
Updated: August 9, 2020
Also i'd like the font to be smaller too if that's possible?
Hi there,
Also i’d like the font to be smaller too if that’s possible?
Do you want the whole date post meta to be smaller or just the "Updated:"?
As for showing adding in the "Updated:" try this PHP snippet.
add_filter( 'generate_post_date_output', db_modified_time_stamp, 20, 2);
function db_modified_time_stamp( $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="updated" datetime="%3$s" itemprop="dateModified">Updated: %4$s</time> ' . $time_string;
}
// get modified time and published time. Compare the two, If modified date exists then ouput both time strings with modified date
$updated_time = get_the_modified_time( 'U' );
$published_time = get_the_time( 'U' ) + 86400;
if ( $updated_time > $published_time ) {
$time_string = '<time class="entry-date updated-date" datetime="%3$s" itemprop="dateModified" style="display:inline;">Last Updated: %4$s</time>';
}
$time_string = sprintf( $time_string,
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date('F j, Y') ),
esc_attr( get_the_modified_date( 'c' ) ),
esc_html( get_the_modified_date('F j, Y') )
);
return sprintf( '<span class="posted-on">%1$s</span>', // WPCS: XSS ok, sanitization ok.
sprintf( '<a href="%1$s" title="%2$s" rel="bookmark">%3$s</a>',
esc_url( get_permalink() ),
esc_attr( get_the_time() ),
$time_string
)
);
}
Hi Elvin,
thank you for that code.
It has added the 'updated' part but now the whole thing seems to be clickable and turned into a link?
Also yes I would like the whole thing to be smaller in font. In desktop it looks ok but mobile looks a bit big.
Thanks
Try this modification.
add_filter( 'generate_post_date_output', db_modified_time_stamp, 20, 2);
function db_modified_time_stamp( $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="updated" datetime="%3$s" itemprop="dateModified">Updated: %4$s</time> ' . $time_string;
}
// get modified time and published time. Compare the two, If modified date exists then ouput both time strings with modified date
$updated_time = get_the_modified_time( 'U' );
$published_time = get_the_time( 'U' ) + 86400;
if ( $updated_time > $published_time ) {
$time_string = '<time class="entry-date updated-date" datetime="%3$s" itemprop="dateModified" style="display:inline;">Last Updated: %4$s</time>';
}
$time_string = sprintf( $time_string,
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date('F j, Y') ),
esc_attr( get_the_modified_date( 'c' ) ),
esc_html( get_the_modified_date('F j, Y') )
);
return sprintf( '<span class="posted-on">%1$s</span>', // WPCS: XSS ok, sanitization ok.
$time_string
);
}
and then add this CSS to control the size on mobile.
@media (max-width:768px){
time.entry-date.updated-date {
font-size: 12px;
}
}
Adjust the value to your preference. :D
That worked great. Thank you.
Nice one. No problem. :D