Change destination author link

To only edit the link associated with authors, in the functions.php of your theme:

add_filter( 'author_link', 'new_author_link', 10, 1 );

function new_author_link( $link ) {      
    $link = 'http://newlink.com/'; //set this however you wish

    return $link; //after you've set $link, return it to the filter              
}

If you’re looking to do something like set each author’s link to an existing wp page of the same name (untested example):

add_filter( 'author_link', 'new_author_link', 10, 3 );
function new_author_link( $link, $author_id, $author_nicename ) {

     $page = get_page_by_path( $author_nicename );

     if ($page) { 

         $page = $page->ID;
         $link = get_permalink( $page ); 
     }
     else {
        $link = ''; //some default value perhaps
     }
     return $link;
}

More from WP Codex on Filtering the Author

More from WP Codex on Filters in general.


For your updated example:

If you’re trying to redirect all author links to home_url( 'link' )

add_filter( 'author_link', 'new_author_link', 10, 1 );

function new_author_link( $link ) {         
    $link = home_url( 'link' ); //set this however you wish

    return $link; //after you've set $link, return it to the filter                
}

If you’re trying to achieve some other conditional if/else:

add_filter( 'author_link', 'new_author_link', 10, 1 );

function new_author_link( $link, $author_id, $author_nicename ) {         
    //send author with id one to home link
    if ($author_id == '1') {
         $link = home_url( 'link' ); //set this however you wish
    }
    //send all other authors to some other link
    else {
        $link = 'http://sitename.com/some-other-url/';
    }

    return $link; //after you've set $link, return it to the filter                
}

Leave a Comment