At the moment I have the following code for changing the author_base slug.
/** ADD REWRITE RULES **/
function change_author_permalinks() {
global $wp_rewrite;
$wp_rewrite->author_base = 'profile';
$wp_rewrite->flush_rules();
}
add_action('init','change_author_permalinks');
How can I add, for example, a extra “edit” page on to this, i.e., /profile/my-user-name/edit ???
The author rewrite rules are filtered through
author_rewrite_rules
. You can add a rule there for the patternauthor/([^/]+)/edit/?$
, but the substitution will depend on how you want to create theedit
page. A simple example that will set a custom query variable and load a specific template if this variable is set:Small tip: Don’t call
flush_rules()
on everyinit
, it’s an expensive operation. You only need to do it when the rewrite rules change. You can manually flush the rules by just visiting the Permalinks settings page. And if you are going to play with the rewrite rules, I recommend you install my Rewrite analyzer plugin.