How to custom change author base without $this->front?

I have a sample code:

function change_author_permalinks() {
    global $wp_rewrite;
    $wp_rewrite->author_base="u";
    $wp_rewrite->author_structure = "https://wordpress.stackexchange.com/" . $wp_rewrite->author_base . '/%author%';
    add_rewrite_rule('u/([^/]+)/?$', 'index.php?author_name=$matches[1]', 'top');
}
add_action('init','change_author_permalinks');

but my current front set on my blog is:

t%post% (ex: www.domain.com/tauthor/username)

I want change to:

www.domain.com/u/username

But when run code, result is page not found ? How to fix it ?

2 Answers
2

You’re close, but you don’t need the add_rewrite_rule call.

add_action('init', 'wpse82004_init');
function wpse82004_init()
{
    global $wp_rewrite;
    $wp_rewrite->author_base="u";
    $wp_rewrite->author_structure="https://wordpress.stackexchange.com/" . $wp_rewrite->author_base . '/%author%';
}

After that’s in place, just re-save permalinks.

Here’s a plugin to put an option on your permalinks page to do this.

Leave a Comment