4

I am currently using this code:

function change_author_permalinks() {
    global $wp_rewrite;
    $wp_rewrite->author_base = 'connect/member';
}
add_action('init','change_author_permalinks');

but my current front set on my blog is:

share

So the above generates a URL like so:

http://example.com/share/connect/member/john-smith

But I don't want /share/ as part of this author URL. I cannot remove the /share/ front as it is needed for other parts of the site.

How do I set the author URL to not use front?

1 Answer 1

3

This is the best solution I have come up with but I welcome better ways:

function change_author_permalinks() {
    global $wp_rewrite;
    $wp_rewrite->author_base = 'connect/member';
    $wp_rewrite->author_structure = "/" . $wp_rewrite->author_base . '/%author%';
    add_rewrite_rule('connect/member/([^/]+)/?$', 'index.php?author_name=$matches[1]', 'top');
}
add_action('init','change_author_permalinks');
1
  • A reminder to all to visit your Settings > Permalinks page after making this change to functions.php in order to refresh your site's permalinks. Before I had done that my author base was properly changed, but the link returned a 404. (WordPress still had the author page living at /front/authors/username.)
    – Darren
    Commented Jun 23, 2017 at 0:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.