- This topic has 15 replies, 4 voices, and was last updated 5 years, 6 months ago by Tom.
-
AuthorPosts
-
June 6, 2018 at 3:23 am #592942Carson
Hi,
I read a few threads about this on here already, but unfortunately I lack the coding skills to achieve my desired results, using one of the answers you guys already gave.
So I want to change the Post meta to display something like this:
Written by [Author]|Last updated on August 15, 2017
Appreciate any help!
June 6, 2018 at 4:40 am #592975LeoStaffCustomer SupportHi there,
Have you tried this?
https://docs.generatepress.com/article/show-the-updated-post-date/Let me know.
June 6, 2018 at 7:21 am #593086CarsonThat already helps a lot, thanks!
Two more questions:
How would I move the author in front of the date?
How do I make so the date isn’t a link?June 6, 2018 at 9:01 pm #593641TomLead DeveloperLead DeveloperThat should be possible with a filter.
First, disable the author inside of the Customizer.
Then add this function:
add_filter( 'generate_post_date_output', 'tu_author_in_front_of_date', 10, 2 ); function tu_author_in_front_of_date( $date, $time_string ) { $author = sprintf( ' <span class="byline">%1$s</span>', // WPCS: XSS ok, sanitization ok. sprintf( '<span class="author vcard" itemtype="https://schema.org/Person" itemscope="itemscope" itemprop="author">%1$s <a class="url fn n" href="%2$s" title="%3$s" rel="author" itemprop="url"><span class="author-name" itemprop="name">%4$s</span></a></span>', __( 'by','generatepress'), esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), /* translators: 1: Author name */ esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), get_the_author() ) ), esc_html( get_the_author() ) ) ); $date = sprintf( '<span class="posted-on">%s</span>', $time_string ); return $author . $date; }
June 17, 2018 at 2:47 am #601931CarsonThis doesn’t work unfortunately.
With and without the snippet it doesn’t result into what I need.
“Written by Author | Last updated on April 21, 2018”
Also for some reason the snippet doesn’t work anymore to show the “Last update date”.
June 17, 2018 at 8:55 am #602114TomLead DeveloperLead DeveloperThat’s strange – I just tested it and it’s working for me.
How did you add the function?
June 17, 2018 at 11:25 am #602168CarsonI used the Code Snippets plugin to add the snippet.
June 17, 2018 at 9:41 pm #602347TomLead DeveloperLead DeveloperAnd it’s activated? Can you link me to your site with the snippet added?
June 18, 2018 at 4:30 am #602546CarsonEDIT:
I think the problem was that I placed it at the bottom of my CSS file, now it’s working fine. Thanks a lot!
June 18, 2018 at 8:14 am #602776TomLead DeveloperLead DeveloperAwesome, glad I could help ๐
September 27, 2018 at 12:01 pm #688019EvgeniyaHi,
I have tried to add filter in post #593641, but it did something strange. It just repeated post updated date and author meta 2 times.
Maybe it has something to do whith my other filter:
add_filter( ‘generate_post_date_output’, ‘tu_show_modified_date’ );
function tu_show_modified_date() {
$time_string = ‘<time class=”entry-date published” datetime=”%1$s” itemprop=”datePublished”>%2$s</time>’;if ( get_the_time( ‘U’ ) !== get_the_modified_time( ‘U’ ) ) {
$time_string = ‘<time class=”updated” datetime=”%3$s” itemprop=”dateModified”>%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() )
);printf(
‘<span class=”posted-on”>%1$s</span>’, // WPCS: XSS ok, sanitization ok.
sprintf( ‘%3$s‘,
esc_url( get_permalink() ),
esc_attr( get_the_time() ),
$time_string
)
);
}I just wanted post meta in this order: Author: + Gravatar + author’s name + Last updated: + date
Can you help me with this?September 27, 2018 at 8:19 pm #688232TomLead DeveloperLead DeveloperWhat’s that function doing exactly?
I assume you have other functions to add the gravatar?
Let me know ๐
September 27, 2018 at 11:14 pm #688272EvgeniyaThat function shows modified date with words “Last updated” but only if post was updated. If post was not updated it shows published date without words “Last updated”.
I deleted previous function to add Gravatar because it looked like it repeats half of the code to show author and the date in post #593641.September 28, 2018 at 9:51 am #688742TomLead DeveloperLead DeveloperInstead of that function you can just do this: https://docs.generatepress.com/article/show-the-updated-post-date/
September 29, 2018 at 1:41 am #689174EvgeniyaHi Tom,
I have added CSS for post updated date like you suggested. So far it works fine. But i have few more questions about function in post #593641:
– How can i add gravatar foto in there?
– How do i make an interval between author’s meta and date? Because now date appears right after author’s meta without even slightest gap.
– How can i make all this post meta appear in this form only in single posts? And in the main page and archive page only show date? Because now in main page and archive page shows author’s meta although i checked off “Display post author” in Customizer. -
AuthorPosts
- You must be logged in to reply to this topic.