- This topic has 9 replies, 5 voices, and was last updated 8 months ago by
David.
-
AuthorPosts
-
December 11, 2019 at 11:35 am #1101367
John
I would like to change the title of author archive pages to display as something like ‘Posts by (author name)’ instead of just ‘(author name)’.
This is controlled by the generate_archive_title function, but if I change something there then it will add the ‘Posts by’ to all archive page titles.
So, basically I want to change
<h1 class="page-title"> <?php the_archive_title(); ?> </h1>
to
<h1 class="page-title"> Posts by <?php the_archive_title(); ?> </h1>
on author archive pages only.
What is the best way to do that?
December 11, 2019 at 12:39 pm #1101417Leo
StaffCustomer SupportHi there,
Would a CSS solution like this work for you?
.archive.author h1.page-title span.vcard:before { content: "Posted by: "; }
Adding CSS: https://docs.generatepress.com/article/adding-css/
Let me know if this helps π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/December 11, 2019 at 1:22 pm #1101477John
Yep, that could work I think. It definitely works from a visual point of view.
Just wondering how do search engines, etc. read and index that. Will they read the part added with CSS as part of the page title and index as “Articles by Bob” or just index it as “Bob”?
December 11, 2019 at 7:02 pm #1101635Tom
Lead DeveloperLead DeveloperHi there,
For search engines to read/index it, you’d have to add this PHP instead.
add_filter( 'get_the_archive_title', function( $title ) { if ( is_author() ) { the_post(); $title = sprintf( '%1$s Posted by: <span class="vcard">%2$s</span>', get_avatar( get_the_author_meta( 'ID' ), 75 ), get_the_author() ); rewind_posts(); } return $title; } );
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentDecember 12, 2019 at 8:23 am #1102315John
Thanks Tom, that sounds like the solution I was looking for. I will give it a try this morning!
December 12, 2019 at 9:44 am #1102377Tom
Lead DeveloperLead DeveloperNo problem π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentDecember 12, 2019 at 11:55 am #1102510John
Working perfectly, thanks.
December 12, 2019 at 4:50 pm #1102716Tom
Lead DeveloperLead DeveloperAwesome, you’re welcome!
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentMay 19, 2020 at 3:10 am #1291511Fabien
Hi,
Is this function still supposed to work ? I am trying it but no luck so far…
May 19, 2020 at 3:28 am #1291537David
StaffCustomer SupportHi there,
yes it should still work.
If you want to raise a new topic where you can share a link to your Author page and we can take a look.Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/ -
AuthorPosts
- You must be logged in to reply to this topic.