[Resolved] Display original date and last update date

Home Forums Support Display original date and last update date

Viewing 15 posts - 1 through 15 (of 21 total)
  • Author
    Posts
  • #1129054
    Gian

    Hi everyone,

    On single blog posts I would like to display the post date where the article was first published and, if modified later, also the last updated date.

    I’ve tried to follow this guide https://docs.generatepress.com/article/show-the-updated-post-date/ and this one https://docs.generatepress.com/article/generate_post_date_output/#only-show-updated-date but with no luck.

    Do you have any idea how to achieve this?

    Thank you in advance

    #1129285
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    It seems to be working on single posts – can you double-check?: https://www.screencast.com/t/Zr426YJ5

    Let me know 🙂

    #1130677
    Gian

    Hi Tom, thank you for getting back to me.

    Yes, I was able to display the “last update” date but I’d like also to display the date when the article was first published.

    Let’s say that I have a blog post published on 12 December 2019 and the same article was updated on the 6 January 2020; is it possible in this case to achieve something like:

    Avatar + Author Name | 12 December 2019 | Last updated: 6 January 2020

    And not displaying the “Last updated” date if no edits were made to the original blog post?

    So only Avatar + Author Name | 12 December 2019 in case that the article is not updated?

    Also, I’d like to rearrange the order of the Entry Meta Style like the Example 1 showed here https://docs.generatepress.com/article/entry-meta-style/ but now it show the author name twice as you can see from here https://imgur.com/DzHDjlF

    Any idea?

    Thank you in advance for your help.

    #1130788
    Tom
    Lead Developer
    Lead Developer

    In that case, try removing this CSS:

    .posted-on .updated + .entry-date {
        display: none;
    }

    As for the duplicate author name, are you using any other filters targeting the post meta?

    #1130826
    Gian

    Thanks!

    Removing the CSS worked but now there’s no space between the 2 dates https://imgur.com/7XpKv2z

    How do I add the space and reorder to have Avatar + Author name | Original date | Last updated date?

    For the post meta I’m using the following CSS:

    .posted-on .updated {
        display: inline-block;
    }
    
    .posted-on .updated:before {
        content: "Ultimo aggiornamento: ";
    }
    

    and this one:

    .byline img {
        width: 25px;
        height: 25px;
        border-radius: 50%;
        position: relative;
        vertical-align: middle;
        margin: 0 10px 0 0;
    }
    
    .comments-link,
    .posted-on {
    	border-left: 1px solid #ddd;
    	padding-left: 10px;
    	margin-left: 10px;
    }

    and the 2 snippets below:

    add_filter( 'generate_post_author_output', function() {
        printf( ' <span class="byline">%1$s</span>',
            sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%1$s <span class="fn n author-name" itemprop="name">%4$s</span></span>',
                __( 'by','generatepress'),
                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() )
            ) 
        );
    } );
    add_filter( 'generate_post_date_output', function( $output, $time_string ) {
    	printf( '<span class="posted-on">%s</span>',
    		$time_string
    	);
    }, 10, 2 );

    to remove links from author name and post date.

    And also the php snippet in the Example 1 here https://docs.generatepress.com/article/entry-meta-style/

    #1131187
    Tom
    Lead Developer
    Lead Developer

    Try this CSS:

    .posted-on {
        display: inline-flex;
    }
    
    .entry-date {
        order: -1;
        margin-right: 10px;
        border-right: 1px solid #ddd;
        padding-right: 10px;
    }

    As for the double author, what are you doing with the generate_post_author_output filter above (not in Example 1)?

    We’ll need to merge the two filters so there aren’t two of them.

    Let me know 🙂

    #1131852
    Gian

    Hi Tom, the CSS worked 🙂 thank you!

    I added the generate_post_author_output in the PHP snippet listed here https://docs.generatepress.com/article/generate_post_author_output/#remove-link to remove link from the Author name.

    #1132325
    Tom
    Lead Developer
    Lead Developer

    Ok, so instead of that, use this filter to add the avatar and remove the link:

    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' ) )
            )
        );
    } );
    #1132450
    Gian

    Working now, thank you for your help! 🙂

    #1133117
    Gian

    Hi Tom, one last thing; is there a way to reduce font size for Author Name + Dates?

    Thank you

    #1133173
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    This should do it:

    .entry-meta {
        font-size: 11px;
    }
    #1133185
    Gian

    Thank you! 🙂

    #1133531
    Tom
    Lead Developer
    Lead Developer
    #1134421
    Gian

    Hi Tom, sorry to bother you again.

    I noticed that the function “last updated” date on my blog, hide the post date in SERP (example: https://imgur.com/T2sF4rD).

    Is that normal or is there a way or code/snippet to display the date of the post in SERP?

    Thank you

    #1134596
    Tom
    Lead Developer
    Lead Developer

    It’s typically up to Google whether to display it or not.

    Some people have noticed that it displays more consistency if the updated date is the only date on the page, which would require removing the published date completely from the HTML (possible if you’d like).

    If not, do you have any examples of pages that include both dates, yet show the published/updated date in search engines? Would love to check out their HTML for clues.

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