Site logo

Archived topic

Page Hero

7 replies · Started by Jim on August 13, 2019

Viewing posts 1–8 of 8

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

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?

Okay, thanks.

No problem :)

This archived topic is closed to new replies.