- This topic has 6 replies, 3 voices, and was last updated 3 years, 9 months ago by Tom.
-
AuthorPosts
-
June 27, 2020 at 10:56 am #1343849Emmanuel
Hi Tom,
I have read through the forum and managed to display Updated Date on Page Hero using this shortcode:
I have also read this post: https://docs.generatepress.com/article/generate_post_date_output/#only-show-updated-date and added the code in my functions.
Then I read here that one should only display the modified date in order for Google to display it in results. My test in structured data shows both updated and published date.
How can I completely disable published date so that Google could pick it up? He did not mention how he solved it.
Thanks
June 27, 2020 at 5:07 pm #1344061LeoStaffCustomer SupportHi there,
Is this issue still happening?
I’m only seeing updated date now.
June 27, 2020 at 11:14 pm #1344170EmmanuelHi Leo,
Yes, it is still happening.On Google, it is showing the published dates for articles rather than the updated date.
When I use this code provided by Tom the date is not displayed.
June 27, 2020 at 11:54 pm #1344194EmmanuelHello,
So I added this code that Tom Provided:
function display_modified_date_shortcode () { $mod_date = get_the_modified_date(); if ( get_the_date() !== $mod_date ) { return sprintf( 'Updated On <time class="updated" datetime="%1$s" itemprop="dateModified">%2$s</time>', esc_attr( get_the_modified_date( 'c' ) ), esc_html( $mod_date ) ); } } add_shortcode( 'modified_date', 'display_modified_date_shortcode' );
But the date does not display because of this CSS
.page-hero time.updated { display: none; }
Another thing I noticed is that if a post has not been updated the Updated Date will not show completely.
June 28, 2020 at 10:28 am #1344687TomLead DeveloperLead DeveloperHi there,
You’re better off using the
{{post_date}}
template tag and doing this:add_filter( 'generate_page_hero_post_date', function() { $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' ) + 1800; if ( $updated_time > $published_time ) { $time_string = '<time class="entry-date-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 $time_string; } );
June 28, 2020 at 12:38 pm #1344765EmmanuelHi Tom,
Thanks. This works as expected.
Regards
June 28, 2020 at 1:49 pm #1344818TomLead DeveloperLead DeveloperYou’re welcome 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.