At the end of most articles in most WordPress blogs, you may have noticed an author bio, along with the author’s archive link. Depending on the WordPress theme in use, the author archive link is usually also displayed wherever post roll ups (blogroll, taxonomy archives, search pages, etc.) are shown on the site – often below post titles. Something like this:
The way WordPress handles these URLs is actually one of the excellent features of the CMS. Its several URL structures allow you to present links to your content in different ways. Thanks to the flexibility of WordPress’ URLs, you can load all the articles of any particular author with just a click.
On blogs with just one author, however, the author archive link is often useless because it generally displays a roll up of articles similar to what is already on the homepage. In such cases, an author archive just causes content duplication and redundancy. There’s really no benefit keeping the archive.
Point The Author Archive To Your About Page
A smart way to do away with the author archive link is to point it to some other URL on your site that would provide some more value to your readers. This could be an about page, or something similar.
This piece of code achieves that. Copy and paste it in your theme’s functions.php file.
// Redirect all author archives to the website's about page add_filter('author_link', 'ehi_author_link'); function ehi_author_link() { return home_url('about'); }
Simply replace “about” with the slug of the page to which you want to redirect your author archive link. Save the changes and reload a post page. Click the author’s name, or whatever text holds the author archive link. You will notice you will be redirected to the page you defined in the above code snippet.
Use the above piece of code with caution though. Because its effect is global across your website. If you have that code in place and later add a contributor to your site, you may wonder why the new contributor’s author link points to the old author’s about page.
For this reason, even for single author websites, I prefer and recommend using the more specific multi-author version of the code (see below).
The following snippet illustrates this method if you have multiple authors. The code first checks for the user ID before changing the author archive link. Simply specify the ID of the user whose author archive you want to change. In the code example below, I have used an ID of 1 (which is the ID of the admin user on most single author sites).
// Redirect author archive to the website's about page [if author ID is 1] add_filter('author_link', 'ehi_multi_author_link', 10, 2); function ehi_multi_author_link($url, $user_id) { if (1 === $user_id) { return home_url('about'); } return $url; }
Now, you have successfully removed (hidden) your WordPress author archive link everywhere. So no users will be able to find the original link and click on it. They will always see your defined “about” page instead.
But what about those “smart” users who try to guess your author archive link and type it directly into the browser? The above methods can’t help to prevent such access. Instead we need to perform an actual redirect (template_redirect).
Redirecting Your WordPress Author Archive Link
Copy the following code snippet and paste in your functions.php file.
// Redirect author archive when visited directly [if author ID is 1] add_action('template_redirect', 'ehi_redirect_author_archive'); function ehi_redirect_author_archive() { if (is_author('1')) { wp_redirect(home_url('about'), 301); exit; } }
Remember to change “about” to the slug of your desired page. I used a 301 (permanent) redirect. You may wish to change yours to a 302 if you want a temporary redirect.
Again the above code checks if the author ID is 1. If you want to do this redirection for all authors, just use the is_author() function without passing any parameters.
Single Author Versus Multi Author
WordPress has an in-built function, is_multi_author() that allows you to check if articles have been written by more than one author on a website. Some theme developers use it to display a profile box at the end of an article.
Using this function, you can check if there are multiple authors with published posts, and based on this condition, display or hide the name of the author. The code snippet below is a sample of how this can be achieved.
is_multi_author() ? the_author_posts_link() : the_author();
Conclusion
This article has shown how you can change or redirect the author archive link by wrangling with code a little bit. Play around with the code snippets and come up with something that works great for your unique use case.
I’ll be lurking around in the comments section to answer any questions you might have.
Leave a Reply