[Support request] Show posted Updated date automatically

Home Forums Support [Support request] Show posted Updated date automatically

Home Forums Support Show posted Updated date automatically

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #2355530
    Techibytes Media

    so I bought the premium theme but at the moment downgraded to the free theme because of ezoic errors. So I want to know how you can help me in showing article’s edited date while the original date remains.

    #2355896
    Fernando
    Customer Support

    Hello there,

    You can try adding a filter like this:

    add_filter( 'generate_post_date_output', function( $output, $time_string ) {
    	
    $time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">Published on %2$s</time>';
    
    if ( get_the_date() !== get_the_modified_date() ) {
    	$time_string = '<time class="entry-date updated-date" datetime="%3$s" itemprop="dateModified">Updated: %4$s</time>
    	<time class="entry-date published" datetime="%1$s" itemprop="datePublished">Published: %2$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 );

    Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets

    #2417272
    Kumara

    Thanks Fernando,

    Would it be possible to use that snippet within a header element? I’m currently using {{post_date}} but I’d like to automatically show the modified date instead if one exists.

    Thanks!

    #2417316
    Ying
    Staff
    Customer Support

    I would recommend using block element – post meta template.

    #2418842
    Kumara

    Thanks Ying! I was able to get the published/updated date working within the post meta template. Is it possible to pull the template into a header (hero image) element?

    #2418982
    Fernando
    Customer Support

    Hi Kumara,

    What type of Header – Hero Image are you planning to create?

    Perhaps using a Block Element – Page Hero would be more appropriate? Reference: https://docs.generatepress.com/article/block-element-page-hero/

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