Set a custom rewrite rule for author archives in WordPress

In the comments of my post on custom rewrite rules in WordPress, I received a query regarding creating author profile URLs using a rewrite convention of “/profile“.

The WordPress author archives are a great way to create profiles for each author on your WordPress-powered website (in fact, it’s done for you by default). The author archives also make use of the “author.php” template file, if it exists in the theme, allowing for easy additions of custom information about the author, custom content from various areas of your website or links to their social media profiles. The question is, how can we leverage this and still have “/profile” as a part of the URL to each author’s archive screen?

Below is a GitHub Gist of a small plugin I compiled to handle this. This plugin uses the WordPress Rewrite API to modify the “/author” part of the author archive URLs to read “/profile” instead.

How do I use this custom rewrite rule?

To use this, save this into a new PHP file (using a code editor of your choice, or a “Plain Text” file in TextEdit (OS X) or Notepad (Windows). From there, save this new file into the “wp-content/plugins” directory of your WordPress installation. This may require the use of FTP to get the code onto your server, should the installation be on a live website. Once uploaded, activate it via the “Plugins” screen in your WordPress admin.

Note: You’ll need to re-save your permalinks settings under the “Settings > Permalinks” screen after activating this plugin, as the plugin doesn’t automatically flush the rewrite rules on activation.

If you’ve ever needed to do this on a project, give this a try and let me know what you think in the comments below. ๐Ÿ™‚

4 responses to “Set a custom rewrite rule for author archives in WordPress”

    • Hey Matt,

      The “How to change the author URL” section of Yoast’s post, where he filters on “author_link”, could potentially override this, I believe. It’s unclear as to whether the “author_link” there is the URL filled in on the author’s profile, or their author archive screen in WordPress, where their posts are listed (I suspect it’s the former, though).

      • Awesome, thanks ๐Ÿ™‚ I have been playing a little bit with author archives lately, WordPress just handles and thinks of everything straight out the box and your post was at the perfect time as well!

Leave a Reply

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

%d bloggers like this: