Archived topic
Change author URL
7 replies · Started by Paul on September 28, 2019
Hello,
I want to change the author URL from the default location to a location specified by me. I currently have a 301 in place to achieve this but would like to remove the redirect hop and have it "hard coded".
Please let me know if this is possible.
Thanks Paul
Hi there,
you can use the PHP filter provided here:
https://docs.generatepress.com/article/generate_post_author_output/#custom-author-name
Thanks David - how would I adapt this for a multi author site. I don't have a huge amount of authors so do I just repeat the function with each author specified? If so could you provide the correct syntax
Little more complicated - try this instead:
add_filter( 'author_link', 'switch_author_links', 10, 2);
function switch_author_links( $url, $user_id) {
switch($user_id) {
case "100":
return home_url( 'author_slug_1');
break;
case "200":
return home_url( 'author_slug_2');
break;
case "300":
return home_url( 'author_slug_3');
break;
}
return $url;
}
Create a case for each author ID and return the page_slug for that author.
Example:
case "100":
return home_url( 'author_slug_1');
Author ID of 100 will have a link of mywebsite.com/author_slug_1
You can get each Author ID by going to Users > All users and hovering over the number of Posts they have created, the link at the foot of the browser will include the ID.
worked a treat. Thanks.
Awesome - glad to be of help
Hi,
I would like to do the same change the author URL link but for the example 1 in your doc https://docs.generatepress.com/article/entry-meta-style/?fbclid=IwAR10g-fIphMWMjY9wDMJy8WIy5owvmT1LW6cwolfClAJ_H8XlCLdLRpF4Kg.
thanks for your help.
Hi there,
if you follow the steps in the doc:
Then add the code i provided here with your own IDs and Slugs:
https://generatepress.com/forums/topic/change-author-url/#post-1023639