[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

  • This topic has 25 replies, 3 voices, and was last updated 4 years ago by David.
Viewing 11 posts - 16 through 26 (of 26 total)
  • Author
    Posts
  • #1227262
    David
    Staff
    Customer Support

    Hi there,

    lets try this.

    Find this line:

    if ( get_the_modified_time( 'U' ) > get_the_time( 'U' ) ) {

    and replace it with:

    $pub_time = get_the_time( 'U' );
    $upd_time = get_the_modified_time( 'U' ) + 86400;
    
    if ( $upd_time > $pub_time ) {
    #1227896
    Tan

    Thank you, I tried again but it didn’t work 🙁

    #1228168
    David
    Staff
    Customer Support

    Can you temporarily remove that Code so we can see what the default timestamps are showing ?

    #1228188
    Tan

    Done. I removed that code. Hope to help you.

    #1228763
    Tom
    Lead Developer
    Lead Developer

    Hmm, something weird going on.

    Can you add this? It should output the two variables we’re comparing:

    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>';
    
        $updated_time = get_the_modified_time( 'U' );
        $published_time = get_the_time( 'U' );
    
        var_dump( 'Updated:' . $updated_time );
        var_dump( 'Published:' . $published_time );
    
        if ( $updated_time > $published_time ) {
            $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' );

    Can you share the two values which are output so we can compare them?

    #1229247
    Tan

    Hi Tom,
    These are results: new code and old code
    Thank you for your help.

    #1229555
    David
    Staff
    Customer Support

    Aah i spotted why my effort did not apply 🙂

    In Tom’s latest code, can you change:

    $published_time = get_the_time( 'U' );

    to:

    $published_time = get_the_time( 'U' ) + 86400;

    Make that edit and let us know.

    #1229569
    Tan

    Yeah It worked David. It changes published date’s custom text 😀
    But can you help me to delete “string(18) “Updated:1586155300” string(20) “Published:1586241699″” after author name? It looks like this.

    #1229606
    David
    Staff
    Customer Support

    Remove these two line:

    var_dump( 'Updated:' . $updated_time );
    var_dump( 'Published:' . $published_time );
    #1229632
    Tan

    Awesome. Thank you so much for your support! 🙂

    #1229639
    David
    Staff
    Customer Support

    Glad we could be of help

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