Site logo

Archived topic

Regarding "Updated Date"

6 replies · Started by Mini on August 17, 2020

Viewing posts 1–7 of 7

Hello,

I used this code to show updated post in the article page. But I would like to show updated post date in the SERP as well.Can you help me with the same.

.posted-on .updated {
display: inline-block;
}

.posted-on .updated + .entry-date {
display: none;
}
.posted-on .updated:before {
content: "Last Updated ";
}

Thanks in advanced.

Hi there,

Remove that CSS - and add this PHP snippet to your site:

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

    $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">%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="date-label>Last Updated </span><span class="posted-on">%s</span> ',
        $time_string
    );
}, 10, 2 );

Reference:

https://docs.generatepress.com/article/generate_post_date_output/#only-show-updated-date

This will display ONLY the Updated date on the post if one is available. Otherwise it will show the Published date - both will be prefixed with: Last Updated.

How Google interprets your date is upto it.

Hello David,

I removed CSS and this PHP Snippet to my site.

Moreover,I want to show "Last Updated on" Text before the date in the article page.

How can I do that?

One more issue I found that, now some post is shown last updated date at 2 places. One is below the blog title and one is below the feature image.

Here is a blog link:- https://mywplife.com/email-marketing/rss-to-email/

So you can check on your end as well.

To add the Last Updated on text, try this CSS:

.updated-date:before {
    content: "Last updated on";
}

The second date seems to be inside your content itself - can you see it/a shortcode within the post content when editing the post?

Thanks Tom.

I removed that shortcode, now everything is workinhg fine.

No problem! :)

This archived topic is closed to new replies.