The author_rewrite_rules WordPress PHP filter allows you to modify rewrite rules used for author archives, including pagination and feed paths for those archives.
Usage
add_filter('author_rewrite_rules', 'your_custom_function'); function your_custom_function($author_rewrite) { // your custom code here return $author_rewrite; }
Parameters
- $author_rewrite (string[]): An array of rewrite rules for author archives, keyed by their regex pattern.
More information
See WordPress Developer Resources: author_rewrite_rules
Examples
Add a custom prefix to author archive URLs
Change author archive URLs from /author/author-name/ to /custom-prefix/author-name/.
add_filter('author_rewrite_rules', 'change_author_prefix'); function change_author_prefix($author_rewrite) { $new_rules = []; foreach ($author_rewrite as $pattern => $rule) { $new_pattern = str_replace('author', 'custom-prefix', $pattern); $new_rules[$new_pattern] = $rule; } return $new_rules; }
Remove the author prefix from author archive URLs
Change author archive URLs from /author/author-name/ to /author-name/.
add_filter('author_rewrite_rules', 'remove_author_prefix'); function remove_author_prefix($author_rewrite) { $new_rules = []; foreach ($author_rewrite as $pattern => $rule) { $new_pattern = str_replace('author/', '', $pattern); $new_rules[$new_pattern] = $rule; } return $new_rules; }
Add a custom suffix to author archive URLs
Change author archive URLs from /author/author-name/ to /author/author-name/custom-suffix/.
add_filter('author_rewrite_rules', 'add_author_suffix'); function add_author_suffix($author_rewrite) { $new_rules = []; foreach ($author_rewrite as $pattern => $rule) { $new_pattern = str_replace('(/?)([.$])', '/custom-suffix$1$2', $pattern); $new_rules[$new_pattern] = $rule; } return $new_rules; }
Add custom rewrite rules for author post types
Add custom rewrite rules for a specific custom post type on author archive pages.
add_filter('author_rewrite_rules', 'author_custom_post_type_rules'); function author_custom_post_type_rules($author_rewrite) { $author_rewrite['author/([^/]+)/your-custom-post-type/?$'] = 'index.php?author_name=$matches[1]&post_type=your-custom-post-type'; return $author_rewrite; }
Disable author archive pagination rewrite rules
Remove pagination rewrite rules for author archives.
add_filter('author_rewrite_rules', 'disable_author_pagination'); function disable_author_pagination($author_rewrite) { foreach ($author_rewrite as $pattern => $rule) { if (strpos($pattern, 'paged') !== false) { unset($author_rewrite[$pattern]); } } return $author_rewrite; }