Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 ?

share|improve this question
1  
I'm not familiar with the matter, but what does $this->front has to do with this? As you use it in the title, but not in the content of the Question... –  brasofilo Jan 17 '13 at 16:13
    
Possible duplicate of wordpress.stackexchange.com/questions/77228/… –  chrisguitarguy Jan 18 '13 at 21:04

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

share|improve this answer
    
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. –  helgatheviking Jan 18 '13 at 21:12
    
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. –  chrisguitarguy Jan 18 '13 at 21:16
    
Thanks for clearing that up. I will update my live code based on your answer, so definitely +1 from me! –  helgatheviking Jan 19 '13 at 0:28

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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