[Resolved] Last Updated Display

Home Forums Support [Resolved] Last Updated Display

Home Forums Support Last Updated Display

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1230607
    Subhabrata

    I want to display the following on each of my blog posts.

    “Originally Published On: <Date with Link> and Last Updated On: <Date with Link> by <Author Name> and <Profile Image>

    How to do that?

    #1231189
    David
    Staff
    Customer Support

    Hi there,

    first off add this PHP Snippet to your site:

    add_filter( 'generate_post_author_output', function() {
        return sprintf( ' <span class="byline">%1$s</span>',
            sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%4$s<a href="%1$s" title="%2$s" rel="author"><span class="author-name" itemprop="name">%3$s</span></a></span>',
                esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
                esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), get_the_author() ) ),
                esc_html( get_the_author() ),
                get_avatar( get_the_author_meta( 'ID' ) )
            )
        );
    } );
    
    add_filter( 'generate_header_entry_meta_items', function() {
        return array(
            'date',
            'author',
        );
    } );

    Once thats done i can look at the CSS required to provide the styling and the labels.

    #1232423
    Subhabrata

    Done.

    Please check now.

    It doesn’t give the expected result.

    #1232492
    David
    Staff
    Customer Support

    Now add this:

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

    And then i can provide some CSS to display all dates and style the avatar etc.

    #1232528
    Subhabrata

    Better than previous. But it made author images bigger than needed

    #1232534
    David
    Staff
    Customer Support

    Did you add the code i provided here:
    https://generatepress.com/forums/topic/last-updated-display/#post-1232492

    I cannot see the changes it should make – if you can add it back ill provide the CSS to style it

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