Justin Tadlock

How to change your author archive link

One of the things that has always bugged me about WordPress themes is the author posts URL. This is the URL used to link to your author archive and is a standard piece of data used when showing posts in most themes. The author link is usually in the byline or post meta area of a post.

In general, this is great. For multi-author sites, it allows you to look at a specific author’s posts. However, the author archive is pointless for single-author sites like my blog here because it’s no different than the regular blog/home/posts page.

This tutorial will teach you a few techniques for dealing with this. Most of the code samples in this tutorial should go into a custom functions plugin.

Point the URL to your “about” page

I like this option. Many sites have an “about” or “about me” page. This would be far more useful than another archive listing the same posts listed in your regular posts archive.

The following code will handle that scenario. Just replace about with the slug of the page you want to point to on your site.

add_filter( 'author_link', 'my_author_link' );

function my_author_link() {
    return home_url( 'about' );
}

If you have multiple authors but still want to do this, you can check for the user ID first. Just change the 100 to the ID of the user you want to use this technique for.

add_filter( 'author_link', 'my_multi_author_link', 10, 2 );

function my_multi_author_link( $url, $user_id ) {

    if ( 100 === $user_id )
        return home_url( 'about' );

    return $url;
}

Redirect your author archive

Another technique is to redirect your author archive to the page of your choosing. This is a good option if you don’t want anyone to directly access your author archive at all. The previous technique merely changed the public-facing links to the archive.

The following code will redirect any attempt to access an author archive to your “about” page. You can use 301 for a permanent redirect or leave it at 302 for a temporary redirect.

add_action( 'template_redirect', 'my_redirect_author_archive' );

function my_redirect_author_archive() {

    if ( is_author() ) {
        wp_redirect( home_url( 'about' ), 302 );
        exit;
    }
}

You can also do this for specific author archives by changing is_author() to is_author( $author ). For more information on the is_author() function, check out the function’s page in the WordPress Codex.

What can theme authors do?

If you’re a theme author, you can make checks for single-author vs. multi-author blogs. WordPress has this nifty conditional function called is_multi_author(). It allows you to check whether multiple users have written posts. I sometimes use it when adding an author profile box after single views of posts.

A simple option for displaying an author’s posts URL only if there are multiple authors is the following. It will display the author name if it’s not a multi-author blog.

<?php is_multi_author() ? the_author_posts_link() : the_author(); ?>

Of course, there are other things you can show/hide depending on your theme. The above just illustrates the use of the is_multi_author() function.