[Resolved] How to show published and updated dates

Home Forums Support [Resolved] How to show published and updated dates

Home Forums Support How to show published and updated dates

Viewing 15 posts - 1 through 15 (of 26 total)
  • Author
    Posts
  • #1466881
    Stevie

    Hi guys
    Using the snippet below, my posts update to date of the post revision.
    However I’d still like to keep the original post date in there.
    is there a workaround?

    generate post date output:

    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 );

    #1466990
    David
    Staff
    Customer Support

    Hi there,

    you don’t need that snippet – GP will automatically output both dates if they exist – it just hides the update date. You can change that with this CSS:

    /* Display updated date */
    .posted-on .updated {
        display: inline-block;
        margin-right: 1em;
    }
    /*Add date prefixes */
    .posted-on .updated:before {
        content: 'Updated: ';
    }
    .posted-on .entry-date:before {
        content: 'Published: ';
    }
    #1467256
    Stevie

    thanks David, I’ll give that a try on a test site first

    #1467530
    David
    Staff
    Customer Support

    You’re welcome

    #1467723
    Stevie

    Hi David.
    With snippet deactivated and this css added, it appears to only show both dates on category pages.
    Not on blog page or single post pages.
    Ideally when I update a post, I’d like the ‘updated’ date to appear on Google search too.
    Click through from Google and see the date of update, with the original published date below.
    God,Sorry I’m really pestering you today !
    Here’s the test site I’m trying these out on:

    #1467993
    Stevie

    sorry David, that may have been a caching delay – it’s showing up on post pages now.
    Two more questions and that’s it – promise!
    1.Do both these dates show up in serps?
    2.I note the post dates are also hyperlinks to the post. Is that normal in WordPress?
    I’m still using the generate post date snippets code on my main site, and it’s just plain text, not hyperlinked to the post.

    #1468327
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    1. No, I believe Google will only display one (usually the published date when both are active).

    2. It’s linked by default now, but that link was removed in 3.0: https://generatepress.com/generatepress-3-0-a-new-era/

    #1469490
    Stevie

    Thanks Tom.
    With the GP ‘generate post date snippets’ code active on my main site, Google shows only the new date which is my intention for the serps.
    But ideally when a visitor clicks through, I want them to see the original post date as well.
    Obviously the url still shows original date, but only on desktops.
    It seems a pity that WP just doesn’t have it built in to its code. It seems logical to inform the visitor correctly.

    In meantime:
    From my test site, I’ve removed the snippets code,and added David’s suggested css. At present it shows both dates on the site as he said it would.
    I’ll wait and see what Google search displays in coming week or so.

    #1469725
    Tom
    Lead Developer
    Lead Developer

    I’m not sure how Google determines which date to show. However, I’ve noticed that if both dates are visible, they will show the published date for some reason. It’s only when the published date is removed that they display the updated date.

    #1469749
    Stevie

    c’est la Google !
    I still haven’t figured out, after reading enough seo experts opinions to make my head bleed, which
    of the options is the better.
    One argument being that a human visitor is more likely to click through if it says ‘2020’ , as apparently my wise and weighty tomes ( on vintage fashion in my case) aren’t click bait if they are more than a year old.Mine go wayyy back to the ancient days of 2009. Some of the world’s libraries go back even further apparently!
    If I could add that GP ‘generate post date output snippet’ just for specific posts then I would have the best of both worlds.
    Thanks anyway Tom !

    #1470822
    Tom
    Lead Developer
    Lead Developer

    We’re exploring a Blog Element that will allow for blog settings to be applied conditionally using Display Rules – should happen soon πŸ™‚

    #1471426
    Stevie

    That’s great. Look forward to seeing that option.
    Thanks Tom

    #1606111
    culpable

    Heya Tom,

    Just tacking on to this – I found your filter here form the article you linked (for those that would like the direct link, it’s here.

    Tom I currently have the updated date showing on the front end, but both are present in the schema (I’m intentionally not using the snippet above).

    Instead of the above solution – is there a way for me to make the published date = the last updated date?

    So the “Published date” schema will still end up showing in the source code, but it will be equal to the “Last Updated” date.

    From what I’ve seen analyzing other sites, this seems to be the best way to get Google to recognize that the page has been updated.

    Thank you so much for your help! πŸ™‚

    #1606967
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    That is basically what this filter does: https://docs.generatepress.com/article/generate_post_date_show_updated_only/

    It completely replaces the published date in the HTML with the updated date, so only one date is present in the HTML. There should be no other schema unless it’s being added by a plugin.

    #1608688
    culpable

    Heya Tom,

    Thanks for helping me out.

    To clarify: I want both schema present, I just want the published date to be equal to the last updated date. See πŸ‘‰πŸ» https://imgur.com/Yw8kxwW πŸ™‚

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