- This topic has 6 replies, 3 voices, and was last updated 3 years, 8 months ago by Tom.
-
AuthorPosts
-
August 17, 2020 at 12:54 am #1405729Mini
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.
August 17, 2020 at 4:39 am #1405970DavidStaffCustomer SupportHi 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.
August 17, 2020 at 7:16 am #1406199MiniHello 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?
August 17, 2020 at 10:33 am #1406597MiniOne 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.
August 17, 2020 at 1:35 pm #1406828TomLead DeveloperLead DeveloperTo 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?
August 17, 2020 at 11:48 pm #1407193MiniThanks Tom.
I removed that shortcode, now everything is workinhg fine.
August 18, 2020 at 10:01 am #1408098TomLead DeveloperLead DeveloperNo problem! 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.