How to remove the WordPress author prefix from slug

Heres a little trick on how to remove the WordPress author prefix from the author slug.
To clarify, this snippet will help you turn: ‘http://domain.com/author/peter/‘ into: ‘http://domain.com/peter/‘.

Since we want all links across the site that uses the WordPress author paradigm to auto update without keeping the original links and then redirecting to a new one, We do not want to use any redirects of any kind, but create an actual function in the WordPress functions.php file. We need to add WP rewrite rules to match the names of each of our users in the desired form.

  • The first part of markup hooks into the author_rewrite_rules filter and replaces the author rewrite rules. This retrieves all the user names and adds a rewrite rule specifically for each user (the markup below won’t handle feeds, so look at the WP No Category Base source if you need that).
  • The second part of markup is a function which hooks into the author_link filter and removes the ‘author’ base from the returned URL.

Instructions
Add this code to your functions.php file.
*Remember to flush your rewrite rules after implementing this snippet, by going into “permalinks” within settings and then click “save changes”.

Comments

13 Replies to “How to remove the WordPress author prefix from slug”

    1. Are you sure you cant make it work .. i just used it 3-4 weeks ago, and it worked – maybe you have a conflict in your functions-/plugins-/htaccess?

  1. Thanks, Man. Your trick is the only that worked for me. And I’ve searched across the internet. I hope Google puts this in the first results. Congrats!

  2. I get this : Fatal error: Call to undefined function add_filter() in /home/stark/domains/stark.idl.pl/public_html/wp-includes/functions.php on line 4818
    Can anyone help?

  3. It does work, but also broke the 301 redirections. The “domain.com/?author=1” doesn’t redirect to “domain.com/author_name” anymore.

  4. How can feeds be redirected as well? I tried adding
    $author_rewrite[“({$author->nicename})/(?:feed/)?(feed|rdf|rss|rss2|atom)/?$”] = ‘index.php?author_name=$matches[1]&feed=$matches[2]’;
    but it doesn’t seem to be working

  5. One needs to replace “get_option(‘home’)” with “get_home_url()”, otherwise it will produce non valid urls in case if the home URL is saved with http protocol but the site is on a https (which is quite often a case).

Leave a Reply

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

Snippet Info

Tested with Wordpress v. NA
Review Status: Needs Review

How to remove the WordPress author prefix from slug
4.8 (95.48%) 31 votes
Please report broken snippets.
Report Broken Snippet