- This topic has 25 replies, 3 voices, and was last updated 3 years, 11 months ago by David.
-
AuthorPosts
-
March 30, 2020 at 10:59 pm #1220349Tan
Hi there,
I want to customize entry meta in order: ava author, author name, published date/last updated date, category. Could you help me?
Snippet I used: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_header_entry_meta_items', function() { return array( 'author', 'date', ); } ); add_filter( 'generate_footer_entry_meta_items', function( $items ) { return array( 'date', 'categories', ); } );
March 31, 2020 at 9:20 am #1221050TomLead DeveloperLead DeveloperHi there,
Do you want all of those below the title so it looks like this?:
avatar – author name | published date | updated date | categories
Let me know 🙂
March 31, 2020 at 4:35 pm #1221502TanI want it like:
avatar (no dash between) author name | Published date (or last updated date when I change something) | categories
Thank you for your reply, Tom 🙂April 1, 2020 at 10:12 am #1222439TomLead DeveloperLead DeveloperTry this:
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">%2$s</time>'; if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) { $time_string = '<time class="entry-date updated-date" 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() ) ); 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' );
April 1, 2020 at 6:00 pm #1222887TanThank you so much.
The result like this: https://bit.ly/2R0SaHW
Now, it is showing both published date and updated date. I just want to show one of them. If I updated something it show updated date, if I didn’t updated it show.
And I want to add some custom text before updated date like “Cập nhật vào”.
Could you help me?
Thanks again 🙂April 2, 2020 at 8:52 am #1223769TomLead DeveloperLead DeveloperHmm, it shouldn’t be showing the two dates according to the code I provided. Are you using any other custom function? Specifically, ones that are using the
generate_post_date_output
filter?You can add text before the
<time...
HTML 🙂April 2, 2020 at 5:18 pm #1224270TanAwesome. It deleted old snippet and it worked.
I want to add a custom text when published date is showed and another when updated date is showed. Could you show me the code?
Thank you so much.April 3, 2020 at 4:31 am #1224670DavidStaffCustomer SupportHi there,
in the code Tom provided you have two lines where the $time_string is generated – both shown below where i have added
ADD YOUR TEXT HERE
:1. Published Date
$time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">ADD YOUR TEXT HERE %2$s</time>';
2. Updated Date
$time_string = '<time class="entry-date updated-date" datetime="%3$s" itemprop="dateModified">ADD YOUR TEXT HERE %4$s</time>';
April 3, 2020 at 6:00 am #1224767TanHi David,
Thank you for your help.
I test by adding new post and it shows the text for updated date, not published day 🙁April 3, 2020 at 12:58 pm #1225517TomLead DeveloperLead DeveloperCan you share the full function you’re using?
April 3, 2020 at 3:53 pm #1225657TanIt’s here:
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>'; if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) { $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' );
April 3, 2020 at 5:42 pm #1225712TomLead DeveloperLead DeveloperHave any of the posts only been published and not updated?
April 3, 2020 at 7:48 pm #1225769TanI published a new post for testing few minutes ago.
You can see it in my blog: https://eladiy.com/blog
It shows custom text “Cập nhật ngày”. It should be showed “Đăng ngày” that follow the code.April 4, 2020 at 9:26 am #1226475TomLead DeveloperLead DeveloperInteresting.. Try this instead:
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>'; if ( get_the_modified_time( 'U' ) > get_the_time( 'U' ) ) { $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' );
April 4, 2020 at 6:46 pm #1226867TanI changed the code but it didn’t work 🙁
Could you try again? Thank you. -
AuthorPosts
- You must be logged in to reply to this topic.