[Resolved] Last Updated Date Does Not Show In Google

Home Forums Support [Resolved] Last Updated Date Does Not Show In Google

Home Forums Support Last Updated Date Does Not Show In Google

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #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.

    #792131
    Leo
    Staff
    Customer Support

    Hi 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 πŸ™‚

    #792502
    culpable

    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.

    #792504
    Tom
    Lead Developer
    Lead Developer

    Hi 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 πŸ™‚

    #792545
    culpable

    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)

    #792955
    Tom
    Lead Developer
    Lead Developer

    That 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.

    #793317
    culpable

    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

    #793713
    Tom
    Lead Developer
    Lead Developer

    Sorry about that! I just adjusted my code above to fix the issue.

    #811631
    culpable

    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!

    #811651
    Tom
    Lead Developer
    Lead Developer

    Thanks for the update!

    Google definitely isn’t super consistent with stuff like this – hopefully you start having more consistent results soon.

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.