- This topic has 9 replies, 3 voices, and was last updated 5 years, 2 months ago by Tom.
-
AuthorPosts
-
July 23, 2019 at 1:43 pm #965394Jay
I’m showing the “updated” post date followed by the post author (“Updated: [date] by [name]”) in my entry meta the exact same way it’s being done here: https://woorkup.com/generatepress-review/
Now I want to switch the order around, so it becomes…
By: [name] Updated: [date]
This seems like it should be pretty simple, but I’m having some trouble making it happen.
Any help would be appreciated. Thanks!
July 23, 2019 at 5:15 pm #965487TomLead DeveloperLead DeveloperHi there,
Are you using any functions right now to alter the post meta?
If not, try this PHP:
add_filter( 'generate_header_entry_meta_items', function() { return array( 'author', 'date', ); } );
July 23, 2019 at 7:54 pm #965573JayHey Tom, thanks for the quick reply.
I’m actually using the method described in that article for altering the post meta, which is this…
if ( ! function_exists( 'generate_posted_on' ) ) : /** * Prints HTML with meta information for the current post-date/time and author. */ function generate_posted_on() { $date = apply_filters( 'generate_post_date', true ); $author = apply_filters( 'generate_post_author', true ); //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() ) ); // If our date is enabled, show it if ( $date ) : printf( '<span style="float: left; margin-right: 3px;">Updated:</span><span class="posted-on">%1$s</span>', sprintf( '<a href="%1$s" title="%2$s" rel="bookmark">%3$s</a>', esc_url( get_permalink() ), esc_attr( get_the_time() ), $time_string ) ); endif; // If our author is enabled, show it if ( $author ) : printf( ' <span class="byline">%1$s</span>', sprintf( '<span class="author vcard" itemtype="http://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' ) ) ), esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), get_the_author() ) ), esc_html( get_the_author() ) ) ); endif; } endif;
Thanks!
July 24, 2019 at 8:39 am #966103LeoStaffCustomer SupportYou no longer need that long function if you are using the latest theme version.
Tom’s function should work now 🙂
July 25, 2019 at 4:53 am #966797JayHmmmm, I’m not sure I understand what you mean?
I originally began using this long function a while ago to show the updated post date because it was the only method that successfully caused Google to show the updated date for my posts in its results. I tested the CSS method covered in the GP docs, but it didn’t make this happen.
Has something changed since then?
Thanks.
July 25, 2019 at 9:24 am #967125LeoStaffCustomer SupportYou can use this to change the HTML markup now:
https://docs.generatepress.com/article/generate_post_date_output/#only-show-updated-dateLet me know if this helps 🙂
July 26, 2019 at 10:58 am #968057JayAhhh, I see now. Thanks! So right now I have it as…
by Name • Updated: June 1, 2019
1. How do I change “by Name” to “Written by: Name”?
2. I also wanted to change the author link to a custom ‘about’ page rather than the default author page, so I found this in another thread:
add_filter( 'author_link', 'my_author_link' ); function my_author_link() { return home_url( 'slug' ); }
And that works perfectly except for one thing: the title for the link remains “View all posts by Name”. Is there a way to change that to something else? If not, is there a way to just get rid of title on the author link altogether?
Thanks again for the help!
July 26, 2019 at 5:20 pm #968213TomLead DeveloperLead DeveloperHi there,
This function should handle both issues:
add_filter( 'generate_post_author_output', function() { return sprintf( '<span class="byline">%1$s</span> ', // WPCS: XSS ok, sanitization ok. sprintf( '<span class="author vcard" %5$s>%1$s <a class="url fn n" href="%2$s" rel="author" itemprop="url"><span class="author-name" itemprop="name">%4$s</span></a></span>', __( 'Written 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() ), generate_get_microdata( 'post-author' ) ) ) } );
Let me know 🙂
July 27, 2019 at 12:25 pm #968819JayPerfect! Thanks guys.
July 27, 2019 at 7:51 pm #968945TomLead DeveloperLead DeveloperYou’re welcome 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.