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.
Great minds! I still do not understand why author-pages are so rudimentary: shouldn’t it be some profile/bio page? That you can tailor to your needs, with images (logos, mugshots), links, a contact form?
WP wants to be(come) a CMS, but it only provides posts on an author-page – no pages (‘static content’). My site only has pages (so far), but the author-pages are pretty useless: I want all pages listed there – maybe with a date and some tags – or perhaps even grouped per category (as per the menu structure) – only to entice people to read further.
I downloaded your ‘query posts’ a while ago… still need to tinker with it. Thanks for now!
Hi Justin,
thank you for this useful article! I really needed a solution like this.
However, I think you write a mistake about 301 and 302 redirects: 301 is the permanent redirect and 302 is the temporary.
Good catch! I’ll update the post.
Another possibility could be to use the author link as your G+ profile, now with the recent authorship updates and people using the auth meta tag.
Correct. That will help in displaying rich snippet in Google search results. But it also leads to 1 small problem: there’re will be a lot of outbound links pointing to Google+ and that might decrease website SEO score because author link doesn’t have
rel="nofollow".BTW, thank Justin for great tip. I’ll try it on my blog.
I like the idea you’re working on here. It seems that you solutions assume that the blog is not using the default permalink setting in that you assume the about page is on mysite.com/about where mine, using the default setting is mysite.com/?page_id=22.
I’ve been meaning to explore the idea of changing my permalink style, but I don’t want to break my site.
Thanks for saving me! You have no idea just how ugly it is to have the URL point to my author ID.
Hey. Thanks a lot for that. I’m using that first code to redirect my author links to my about page, and it works great. But how about if I’m using a multilanguage page? Basicaly I’d want my posts in portuguese to take me to the slug ‘info’ and my posts in english to take me to the slug ‘info-en’. How can I do that?
Thanks!