Archived topic
Custom author page
25 replies · Started by Carlo on February 1, 2020
Hi,
the author page at the moment isnt too customizable, is it possible to create a page and use that as the author(s) page. Basically replacing the author's archive with a custom page?
Hi there,
GP doesn't have anything built-in for this.
Perhaps an article like this would help?
https://www.wpbeginner.com/wp-themes/how-to-add-a-custom-author-profile-page-to-your-wordpress/
Is it possible to completely replace it with a static page, like the example in Toms WP Show Posts: https://docs.wpshowposts.com/article/use-static-pages-as-category-archives/
You could try this:
add_filter( 'author_link', function( $link, $author_id ) {
if ( 1 === $author_id ) {
return 'URL TO YOUR AUTHOR PAGE';
}
if ( 2 === $author_id ) {
return 'URL TO ANOTHER AUTHOR PAGE';
}
return $link;
}, 10, 2 );
Just adjust the author IDs to the actual IDs you're targeting.
Hope this helps :)
Cheers Tom,
Got that working well, so in essence, this code overrides all the author links to whatever we set for each author.
if i manually lookup site.com/author/"authorname"/ then the archive is still there but i guess they wont find it. any way to disable it?
If you're using Yoast SEO, this should help: https://kb.yoast.com/kb/disable-enable-author-archives/
If not, this might help: https://wordpress.org/plugins/disable-author-archives/
thanks Tom, hadn't thought of looking at other plugins for disabling the author archive. I use SEOPress instead and i found the same diable feature.
Anyway got it all working now :)
thanks
Awesome, no problem! :)
Hi GP Team,
I tried using the same info above to also override the default archive.php for author archive. However in my Elements I'm using the {{post_author}} tag and despite disabling the author archive page via Yoast, author links still point to //website.com/author/author-name but brings me to the root of the site if I click on the author since I disabled author archives. I'm using Example 2 from the documentation for my Element.
How would I go about getting the {{post_author}} tag to point to my custom author pages? Or should it be automatically going to my custom author pages with the filter above? Perhaps using an actual author.php file would be better in this case?
Thanks.
Just to confirm, are you using this filter?: https://generatepress.com/forums/topic/custom-autor-page/#post-1152285
Have you updated the author ID? That filter should work for the Elements post author as well.
Thanks for the reply Tom.
Correct. I am using https://generatepress.com/forums/topic/custom-autor-page/#post-1152285.
I think I'm just not understanding the author ID piece. From my dashboard I go to Users and then hover over the number in the Posts column of the Users table. This shows me //mywebsite.com/wp-admin/edit.php?author=1. I only have two authors so they are 1 and 2 respectively.
I'm reading ...if ( 1 === $author_id )... with the number 1 being the author ID. Is this correct?
I’m reading …if ( 1 === $author_id )… with the number 1 being the author ID. Is this correct?
That is correct
Thanks David. Interesting. Then my author ID's are correct in this case yet hovering over the author name in a post which has an Element Header still shows //mywebsite.com/author/author-name. My posts are created in Elementor but I do not think that would mess with my Element Header, would it?
I did a random search on my site and the author name in the search results shows //mywebsite.com/author-name which is the expected outcome.
Seems like the filter is not liking the Element Header {{post_author}} tag? I'm using the code from the example here for my Element Header.
I just double-checked our code - we're using the core function which the author_link filter applies to.
Wonder what this could be.. maybe the action order is off..
It's a shot in the dark, but try this:
add_action( 'wp', function() {
add_filter( 'author_link', function( $link, $author_id ) {
if ( 1 === $author_id ) {
return 'URL TO YOUR AUTHOR PAGE';
}
if ( 2 === $author_id ) {
return 'URL TO ANOTHER AUTHOR PAGE';
}
return $link;
}, 10, 2 );
}, 50 );
Thanks Tom. I gave that a shot but no go.
Any other ideas?
Maybe creating custom author pages would be a better route in this case?