• Skip to main content
  • Skip to primary sidebar

Technical Notes Of
Ehi Kioya

Technical Notes Of Ehi Kioya

  • Forums
  • About
  • Contact
MENUMENU
  • Blog Home
  • AWS, Azure, Cloud
  • Backend (Server-Side)
  • Frontend (Client-Side)
  • SharePoint
  • Tools & Resources
    • CM/IN Ruler
    • URL Decoder
    • Text Hasher
    • Word Count
    • IP Lookup
  • Linux & Servers
  • Zero Code Tech
  • WordPress
  • Musings
  • More
    Categories
    • Cloud
    • Server-Side
    • Front-End
    • SharePoint
    • Tools
    • Linux
    • Zero Code
    • WordPress
    • Musings
Home » WordPress » Changing Or Redirecting Your WordPress Author Archive Link

Changing Or Redirecting Your WordPress Author Archive Link

March 20, 2019 by Ehi Kioya Leave a Comment

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:

WordPress Author Archive Link Example

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.

Found this article valuable? Want to show your appreciation? Here are some options:

  1. Spread the word! Use these buttons to share this link on your favorite social media sites.
  2. Help me share this on . . .

    • Facebook
    • Twitter
    • LinkedIn
    • Reddit
    • Tumblr
    • Pinterest
    • Pocket
    • Telegram
    • WhatsApp
    • Skype
  3. Sign up to join my audience and receive email notifications when I publish new content.
  4. Contribute by adding a comment using the comments section below.
  5. Follow me on Twitter, LinkedIn, and Facebook.

Related

Filed Under: Backend (Server-Side), Web Development, WordPress Tagged With: Author Archive, Redirection, Web Development, WordPress

About Ehi Kioya

I am a Toronto-based Software Engineer. I run this website as part hobby and part business.

To share your thoughts or get help with any of my posts, please drop a comment at the appropriate link.

You can contact me using the form on this page. I'm also on Twitter, LinkedIn, and Facebook.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

26,208
Followers
Follow
30,000
Connections
Connect
14,641
Page Fans
Like

POPULAR   FORUM   TOPICS

  • How to find the title of a song without knowing the lyrics
  • Welcome Message
  • How To Change Or Remove The WordPress Login Error Message
  • The Art of Exploratory Data Analysis (Part 1)
  • Replacing The Default SQLite Database With PostgreSQL In Django
  • Getting Started with SQL: A Beginners Guide to Databases
  • How To Create Tooltips Using CSS3
  • How To Use A Custom Bootstrap Template With Laravel
  • SEO Basics – Crawling, Indexing And Ranking
  • How To Stay Relevant In The Tech Space
  • Recently   Popular   Posts   &   Pages
  • Actual Size Online Ruler Actual Size Online Ruler
    I created this page to measure your screen resolution and produce an online ruler of actual size. It's powered with JavaScript and HTML5.
  • Allowing Multiple RDP Sessions In Windows 10 Using The RDP Wrapper Library Allowing Multiple RDP Sessions In Windows 10 Using The RDP Wrapper Library
    This article explains how to bypass the single user remote desktop connection restriction on Windows 10 by using the RDP wrapper library.
  • WordPress Password Hash Generator WordPress Password Hash Generator
    With this WordPress Password Hash Generator, you can convert a password to its hash, and then set a new password directly in the database.
  • Forums
  • About
  • Contact

© 2021   ·   Ehi Kioya   ·   All Rights Reserved
Privacy Policy