[Resolved] Published or Updated Text and Icon for Date

Home Forums Support Published or Updated Text and Icon for Date

Viewing 15 posts - 1 through 15 (of 20 total)
  • Author
    Posts
  • #1388374
    Rohan Verma

    Hello.

    I want to achieve both the published and updated text for the article date on a single post.

    Currently, it’s only showing the updated text for updated article.

    1. Similarly, I want published text for the single time published article.
    2. And I have followed a PHP code for getting date icon on other topic. But the icon is showing after the date. How can I place it before published/updated text?

    #1388666
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    This article should help: https://docs.generatepress.com/article/show-the-updated-post-date/

    Your CSS would look like this:

    .posted-on .updated {
        display: inline-block;
    }
    
    .posted-on .updated:before {
        content: "Last Updated ";
    }
    
    .posted-on .entry-date:before {
        content: "Published ";
    }

    Which code have you added to add the icon? Where’s the icon coming from exactly? A custom SVG?

    #1388684
    Rohan Verma
    #1388695
    Rohan Verma

    According to your given code, the date tag shows double: https://prnt.sc/tuoib7

    I don’t want like this. There will be only one tag. Not both published and updated.

    Either it will show Published for the fresh articles or it will show Updated for the updated articles.

    Hope you understand.

    #1389078
    David
    Staff
    Customer Support

    Hi there,

    in this article:
    https://docs.generatepress.com/article/generate_post_date_output/#only-show-updated-date

    The code has two $time_string variables – only one will be displayed. The first is for the published date, change it to this:

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

    The second line change to this:

    $time_string = '<time class="entry-date updated-date" datetime="%3$s" itemprop="dateModified">Last Updated %4$s</time>';

    #1389173
    Rohan Verma

    Hi David, But your given two strings are similar to that link.

    So, what to change for published and updated?

    #1389192
    David
    Staff
    Customer Support

    The code changes i provided above include the Published and Last Updated labels.
    So your updated code would look 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 %2$s</time>';
    
        $updated_time = get_the_modified_time( 'U' );
        $published_time = get_the_time( 'U' ) + 86400;
    
        if ( $updated_time > $published_time ) {
            $time_string = '<time class="entry-date updated-date" datetime="%3$s" itemprop="dateModified">Last Updated %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 );
    #1389200
    Rohan Verma

    Now, it looks like these two.

    https://prnt.sc/tuzo4t

    https://prnt.sc/tuzmpc

    I don’t want to show both together. Only one needs to show which one is the latest.

    #1389209
    David
    Staff
    Customer Support

    What other post meta related functions have you added to your site ?

    #1389219
    Rohan Verma

    Remove link from date.
    Show author avatar beside the name.
    Author box hook element.

    There are a bunch of css codes but I don’t know any of them conflicting or not. Should I share with you the css codes…

    #1389234
    David
    Staff
    Customer Support

    Its not the CSS.
    It will be either the remove link and/or show avatar.
    Can you share them here

    #1389240
    Rohan Verma

    Show avatar:

    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(
            'author',
            'comments-link',
            'date',
        );
    } );
    #1389241
    Rohan Verma

    Remove link:

    add_filter( ‘generate_post_date_output’,’tu_remove_date_link’, 10, 2 );
    function tu_remove_date_link( $output, $time_string ) {
    printf( ‘<span class=”posted-on”>%s</span>’,
    $time_string
    );
    }

    #1389348
    David
    Staff
    Customer Support

    Remove the ‘remove link’ function

    #1389356
    Rohan Verma

    Thanks. It’s working.

    1. But how to add : symbol after published or updated text?
    2. How can I make the bold font of both author and published/updated text?

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