#13: author_rewrite_rules

The author_rewrite_rules filter makes it possible to modify WordPress’ default rewrite rules for handling author pages.

It is evaluated in WP_Rewrite::rewrite_rules() in the wp-includes/rewrite.php file.

The author_rewrite_rules filter’s single argument takes the form of an array and contains the key/value rewrite pairs for author pages.

Side note: Altering the default author rewrite rules may cause 404’s with pages that were linked prior to the change. IF you’re going to modify the default rules, it is usually best to retain the original rules and set up redirects to the new permastructs. One method is to append a custom query var — such as ‘redirect’ value of ‘true’ — to the original rule(s), then adding a handler to redirect to the new permastruct if the custom query var is present. This way, you get new custom author rewrites and the old ones still work.

Example:

Let’s say you have a site that makes it a point to refer to credited authors as “contributors”. The following will alter your author rewrite rules to point to yoursite.com/contributor/name for author archives.

View the code example on Gist.

**Bonus: Example functions for adding a ‘redirect’ query var and parsing redirects for the old author permastruct.

View the bonus code example on Gist.