- This topic has 20 replies, 2 voices, and was last updated 4 years, 2 months ago by Tom.
-
AuthorPosts
-
January 11, 2020 at 9:38 am #1129054Gian
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
January 11, 2020 at 5:05 pm #1129285TomLead DeveloperLead DeveloperHi there,
It seems to be working on single posts – can you double-check?: https://www.screencast.com/t/Zr426YJ5
Let me know π
January 13, 2020 at 7:39 am #1130677GianHi 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.
January 13, 2020 at 9:07 am #1130788TomLead DeveloperLead DeveloperIn 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?
January 13, 2020 at 9:33 am #1130826GianThanks!
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/
January 13, 2020 at 7:14 pm #1131187TomLead DeveloperLead DeveloperTry 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 π
January 14, 2020 at 7:24 am #1131852GianHi 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.January 14, 2020 at 3:56 pm #1132325TomLead DeveloperLead DeveloperOk, 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' ) ) ) ); } );
January 14, 2020 at 9:07 pm #1132450GianWorking now, thank you for your help! π
January 15, 2020 at 8:46 am #1133117GianHi Tom, one last thing; is there a way to reduce font size for Author Name + Dates?
Thank you
January 15, 2020 at 9:41 am #1133173TomLead DeveloperLead DeveloperHi there,
This should do it:
.entry-meta { font-size: 11px; }
January 15, 2020 at 9:47 am #1133185GianThank you! π
January 15, 2020 at 4:36 pm #1133531TomLead DeveloperLead DeveloperYou’re welcome! π
January 16, 2020 at 12:40 pm #1134421GianHi 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
January 16, 2020 at 6:04 pm #1134596TomLead DeveloperLead DeveloperIt’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.
-
AuthorPosts
- You must be logged in to reply to this topic.