- This topic has 7 replies, 2 voices, and was last updated 1 year, 6 months ago by
Leo.
-
AuthorPosts
-
August 13, 2019 at 2:08 pm #983417
George
Hi. I am trying to create a banner for single posts and have the hook below (from one of the site-library sites). How do I show the updated date?
<h1> {{post_title}} </h1> <p> {{post_author}} | {{post_date}} | {{post_terms.category}} </p>
If it helps, here is the code I use sitewide to display the updated date. I tried to add shortcode to it but apparently the header hook has no option to activate shortcodes.
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 );
August 13, 2019 at 3:15 pm #983449Leo
StaffCustomer SupportHi there,
You are referring to header element/page hero right?
If so this should help:
https://docs.generatepress.com/article/show-the-updated-post-date/#show-the-%E2%80%9Cupdated%E2%80%9D-post-date-in-header-elementLet me know π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/August 13, 2019 at 3:29 pm #983453George
Thanks. Will the modified date shortcode pull from my code above?
August 13, 2019 at 5:22 pm #983517Leo
StaffCustomer SupportProbably better to keep the two separated.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/August 14, 2019 at 6:02 am #983848George
Okay. I ask coz the function above was provided by Tom and it is the only one that works to show google the modified date. So I am assuming the modified date one you provided should work too?
August 14, 2019 at 8:34 am #984109Leo
StaffCustomer SupportThe code provided here:
https://docs.generatepress.com/article/show-the-updated-post-date/#show-the-%E2%80%9Cupdated%E2%80%9D-post-date-in-header-elementis not modifying the HTML markup. It’s simply creating a shortcode for the updated date so that’s what Google should read.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/August 14, 2019 at 10:34 am #984207George
Okay, thanks.
August 14, 2019 at 10:38 am #984213Leo
StaffCustomer SupportNo problem π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/ -
AuthorPosts
- You must be logged in to reply to this topic.