[Resolved] Page Hero

Home Forums Support [Resolved] Page Hero

Home Forums Support Page Hero

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #983417
    Jim

    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 );
    #983449
    Leo
    Staff
    Customer Support

    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 ๐Ÿ™‚

    #983453
    Jim

    Thanks. Will the modified date shortcode pull from my code above?

    #983517
    Leo
    Staff
    Customer Support

    Probably better to keep the two separated.

    #983848
    Jim

    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?

    #984109
    Leo
    Staff
    Customer Support

    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.

    #984207
    Jim

    Okay, thanks.

    #984213
    Leo
    Staff
    Customer Support

    No problem ๐Ÿ™‚

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.