Search code examples
wordpresspermalinks

Replace author url with different one (wordpress)


There are 3 authors in our company blog, each author has own site url in profile settings:

Mike - http://mike.com
Gelens - http://gelens.com
Admin - http://site.com/company/

the links for profiles are:

http://site.com/author/Mike/
http://site.com/author/Gelens/
http://site.com/author/Admin/

I need to replace a link to Admin's page, so, if there is <?php the_author_posts_link(); ?> tag on some page, and the author is Admin, the link must be http://site.com/company/ instead of http://site.com/author/Admin/.

How can I do that?


Solution

  • It looks like the the_author_posts_link function just calls get_author_posts_url to get the link, which passes the link through the author_link filter before returning it. In your theme's functions.php, you could add something like this (untested):

    add_filter( 'author_link', 'admin_author_link', 10, 3);
    function admin_author_link($link, $author_id, $author_nicename) {
        if( $author_id==1 ) {
            $link = 'http://site.com/company/';
        }
        return $link;
    }