Archived topic
Page Hero
7 replies · Started by Jim on August 13, 2019
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 );
Hi 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-element
Let me know :)
Thanks. Will the modified date shortcode pull from my code above?
Probably better to keep the two separated.
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?
The 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-element
is not modifying the HTML markup. It's simply creating a shortcode for the updated date so that's what Google should read.
Okay, thanks.
No problem :)