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. 🙂
Leave a Reply