- This topic has 9 replies, 3 voices, and was last updated 4 years, 3 months ago by
Tom.
-
AuthorPosts
-
January 25, 2019 at 3:14 am #791782
culpable
Hiya,
I have changed the CSS on my site over a week ago as per this guide to only show the last updated date.
After updating many posts on my site the “Last updated” date on Google is yet to change. The site receives a high amount of traffic and as such is presumably crawled by Google a decent amount. In addition, I have used google search console (GSC) to force fetches many times over the last week
As a test case (URL given to admins), 4 days ago I made big updates to a post, then forced a fetch in GSC. As of this post it is yet to update in google with the updated date (https://imgur.com/n5BJMTu.png). I believe it has been seen by Google as the meta title has been changed.
I’m wondering why this might be the case? My hunch is that this “Last updated” is not reflected in the website schema, and is hence being ignored by Google? If so βΒ how can I change this so that the schema reflects this last updated date?
Many thanks for your help.
January 25, 2019 at 8:54 am #792131Leo
StaffCustomer SupportHi there,
Tom’s answer here should answer your question as well:
https://generatepress.com/forums/topic/google-is-not-showing-the-last-updated-date/The post author had a slightly different issue (that updated date is showing on Google) but Tom’s answer should apply to your issue as well.
Let me know if this helps π
January 25, 2019 at 5:57 pm #792502culpable
Thanks Leo.
As per the testing tool, the date modified and published are showing up: https://imgur.com/LhYTBjP
My understanding of how this is picking up the “Date Published” is because right now it’s on the page β it’s just not being displayed (we’re hiding it with CSS).
Is there a way for me to remove the date published from the page, such that only the date modified would show when I run it through the structured data testing tool linked by Tom? (https://search.google.com/structured-data/testing-tool)
Preferably I’d like to trial this with a single page and not all my posts at once.
January 25, 2019 at 6:02 pm #792504Tom
Lead DeveloperLead DeveloperHi there,
You can remove the published date if it’s been modified like this:
add_filter( 'generate_post_date_output', function() { $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">%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">%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 ) ); } );
Then you’d need this CSS:
.posted-on .updated { display: inline-block; }
This is likely something that will be implemented by default in GP 2.3.
Let me know if it helps or not π
January 25, 2019 at 8:48 pm #792545culpable
Thank you for the code Tom!
Before I implement this sitewide via PHP snippet. I’d like to test it on a single page. To do this I’d like to use the “Elements” feature of GP. Do I have to alter the code you’ve posted above?
I should also note that this is a WordPress “page”, not a WordPress “post” (if that matters).
I’m currently using this code https://imgur.com/Cs1snnX to display these dates on the page (as mentioned the “Last updated” date is the only date visually showing on the page [via CSS], but it seems Google is ignoring this and using the published date)
January 26, 2019 at 9:14 am #792955Tom
Lead DeveloperLead DeveloperThat code won’t work inside Elements.
Instead, try this:
add_filter( 'generate_post_date_output', function( $output ) { if ( ! is_single( 10 ) ) { return $output; } $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">%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">%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 ) ); } );
So the code will only take effect on a single post with the ID:
10
You’ll need to change that
10
to the actual ID of your post.January 26, 2019 at 7:37 pm #793317culpable
Thank you for the code Tom!
Could you just do a sanity check for me that it’s got the right parenthesis? I’m getting an error, and the same error is being showed when I check the code via: https://phpcodechecker.com/
Parse error: syntax error, unexpected ')', expecting '{' in your code on line 1 add_filter( 'generate_post_date_output', function( $output ) ) {
Thank you for your help
January 27, 2019 at 9:18 am #793713Tom
Lead DeveloperLead DeveloperSorry about that! I just adjusted my code above to fix the issue.
February 15, 2019 at 4:11 pm #811631culpable
Just to give an update on this β the code seems to be working. Thanks Tom & Leo.
Quite annoyingly though, in some of the pages I’ve tested Google seems to be ignoring the last update date (even when its the only date in the structured data tool).
This holds even when I make large changes to the content β adding 500+ words; changing the ordering, title, meta description, and
<h>
tags. And the way the intro was worded. All of this was done in an effort to *actually* update the post too.tl;dr I’m not sure what filters Google has for them to see a post as updated. But it might need some revising π
Anyway β thanks again guys!
February 15, 2019 at 4:50 pm #811651Tom
Lead DeveloperLead DeveloperThanks for the update!
Google definitely isn’t super consistent with stuff like this – hopefully you start having more consistent results soon.
-
AuthorPosts
- You must be logged in to reply to this topic.