Site logo

Archived topic

Customize entry meta author name, date, category

25 replies · Started by Tan on March 30, 2020

Viewing posts 16–26 of 26

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 ) {

Thank you, I tried again but it didn't work :(

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

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

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?

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.

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

Remove these two line:

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

Awesome. Thank you so much for your support! :)

Glad we could be of help

This archived topic is closed to new replies.