4

I have a sample code:

function change_author_permalinks() {
    global $wp_rewrite;
    $wp_rewrite->author_base = 'u';
    $wp_rewrite->author_structure = "/" . $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

2 Answers 2

16

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 = '/' . $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.

4
  • What does the author_structure part do that isn't handled by the author_base? Just curious, because I've not been using that line and it seems to work. Commented Jan 18, 2013 at 21:12
  • 1
    If you have your permalinks without a "front" it will work. Eg. /%year%/%month%/%postname%. If there is a front (eg. /this-is-a-front/%postname%) it won't work. Commented Jan 18, 2013 at 21:16
  • Thanks for clearing that up. I will update my live code based on your answer, so definitely +1 from me! Commented Jan 19, 2013 at 0:28
  • Don't forget to save your permalinks after adding this code so it flushes the rewrite rules.
    – Christine Cooper
    Commented Sep 18, 2017 at 9:59
4

This is what I did to change the author base:

// change base of author pages- need to save permalinks to take effect
function wpa_82004(){
    global $wp_rewrite;
    $wp_rewrite->author_base = 'people'; // or whatever
}
add_action('init','wpa_82004');

Once you've run this, be sure to re-save your permalinks. (Options->Permalinks) You have to flush your rewrite_rules to even know if this is working.

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.