Site logo

Archived topic

Change author URL

7 replies · Started by Paul on September 28, 2019

Viewing posts 1–8 of 8

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

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

This archived topic is closed to new replies.