[Resolved] Customize entry meta author name, date, category

Home Forums Support [Resolved] Customize entry meta author name, date, category

Home Forums Support Customize entry meta author name, date, category

Viewing 15 posts - 1 through 15 (of 26 total)
  • Author
    Posts
  • #1220349
    Tan

    Hi there,
    I want to customize entry meta in order: ava author, author name, published date/last updated date, category. Could you help me?
    Snippet I used:

    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<span class="author-name" itemprop="name">%3$s</span></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(
            'author',
            'date',
        );
    } );
    
    add_filter( 'generate_footer_entry_meta_items', function( $items ) {
        return array(
            'date',
            'categories',
        );
    } );
    
    #1221050
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Do you want all of those below the title so it looks like this?:

    avatar – author name | published date | updated date | categories

    Let me know 🙂

    #1221502
    Tan

    I want it like:
    avatar (no dash between) author name | Published date (or last updated date when I change something) | categories
    Thank you for your reply, Tom 🙂

    #1222439
    Tom
    Lead Developer
    Lead Developer

    Try this:

    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<span class="author-name" itemprop="name">%3$s</span></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_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 );
    
    add_filter( 'generate_header_entry_meta_items', function() {
        return array(
            'author',
            'date',
            'categories',
        );
    } );
    
    add_filter( 'generate_footer_entry_meta_items', '__return_null' );
    #1222887
    Tan

    Thank you so much.
    The result like this: https://bit.ly/2R0SaHW
    Now, it is showing both published date and updated date. I just want to show one of them. If I updated something it show updated date, if I didn’t updated it show.
    And I want to add some custom text before updated date like “Cập nhật vào”.
    Could you help me?
    Thanks again 🙂

    #1223769
    Tom
    Lead Developer
    Lead Developer

    Hmm, it shouldn’t be showing the two dates according to the code I provided. Are you using any other custom function? Specifically, ones that are using the generate_post_date_output filter?

    You can add text before the <time... HTML 🙂

    #1224270
    Tan

    Awesome. It deleted old snippet and it worked.
    I want to add a custom text when published date is showed and another when updated date is showed. Could you show me the code?
    Thank you so much.

    #1224670
    David
    Staff
    Customer Support

    Hi there,

    in the code Tom provided you have two lines where the $time_string is generated – both shown below where i have added ADD YOUR TEXT HERE:

    1. Published Date

    $time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">ADD YOUR TEXT HERE %2$s</time>';

    2. Updated Date

    $time_string = '<time class="entry-date updated-date" datetime="%3$s" itemprop="dateModified">ADD YOUR TEXT HERE %4$s</time>';

    #1224767
    Tan

    Hi David,
    Thank you for your help.
    I test by adding new post and it shows the text for updated date, not published day 🙁

    #1225517
    Tom
    Lead Developer
    Lead Developer

    Can you share the full function you’re using?

    #1225657
    Tan

    It’s here:

    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<span class="author-name" itemprop="name">%3$s</span></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_post_date_output', function( $output, $time_string ) {
        $time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">Đăng ngày %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">Cập nhật ngày %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 );
    
    add_filter( 'generate_header_entry_meta_items', function() {
        return array(
            'author',
            'date',
            'categories',
        );
    } );
    
    add_filter( 'generate_footer_entry_meta_items', '__return_null' );
    
    #1225712
    Tom
    Lead Developer
    Lead Developer

    Have any of the posts only been published and not updated?

    #1225769
    Tan

    I published a new post for testing few minutes ago.
    You can see it in my blog: https://eladiy.com/blog
    It shows custom text “Cập nhật ngày”. It should be showed “Đăng ngày” that follow the code.

    #1226475
    Tom
    Lead Developer
    Lead Developer

    Interesting.. Try this instead:

    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<span class="author-name" itemprop="name">%3$s</span></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_post_date_output', function( $output, $time_string ) {
        $time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">Đăng ngày %2$s</time>';
    
        if ( get_the_modified_time( 'U' ) > get_the_time( 'U' ) ) {
            $time_string = '<time class="entry-date updated-date" datetime="%3$s" itemprop="dateModified">Cập nhật ngày %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 );
    
    add_filter( 'generate_header_entry_meta_items', function() {
        return array(
            'author',
            'date',
            'categories',
        );
    } );
    
    add_filter( 'generate_footer_entry_meta_items', '__return_null' );
    #1226867
    Tan

    I changed the code but it didn’t work 🙁
    Could you try again? Thank you.

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