3

I'm curious if its possible (and advisable) to change certain directory names and URL structure via customization by themes or plugins. For example, say I wanted the list of all a user's posts to appear at blog.com/people/username instead of at blog.com/author/username...is this possible via customization? If so, would this type of customization be very problematic when it comes to things like forward compatibility with the latest WP updates and such?

Any advice anyone can offer on this would be most appreciated.

Thanks.

Eddie

3 Answers 3

4

@kureikain's answer looks great, and it probably works really well in a wide variety of circumstances.

But for author URLs specifically, there's a simpler way. Change the author_base, like so:

global $wp_rewrite;
$wp_rewrite->author_base = "people";
$wp_rewrite->flush_rules();

You should only need to run this once, perhaps on a plugin activation. Updating WordPress should not affect this solution.

EDIT As @Jan pointed out in the comments, you need to run this on every init. But you only have to flush the rules once.

3
  • +1 You're great! I figured out it should be something like that but don't know how to change!
    – kureikain
    Commented Dec 18, 2010 at 0:52
  • I think you need to set the author_base on every init, otherwise the links WP generates to author pages will be wrong. The flush_rules() only needs to run once, indeed (or flush them by visiting the Permalinks page).
    – Jan Fabry
    Commented Jan 7, 2011 at 14:02
  • @Jan Fabry Good catch. I actually just went back and updated a project thanks to this comment. You rule!
    – MathSmath
    Commented Jan 7, 2011 at 15:56
0

You can use filter generate_rewrite_rules to add new custom url! The first, you add filter to create url! Second, you add new function to handle that URL (display wordpress profile in this case)

add_filter('generate_rewrite_rules', 'axcoto_multi_rate_rewrite');
function axcoto_multi_rate_rewrite(&$wp_rewrite) {
    $wp_rewrite->rules = array_merge(array('people/([^/]*)$' => 'index.php?pagename=people&username=$matches[1]'), $wp_rewrite->rules);
    return $wp_rewrite;
}

That way when someone go to people/kureikain, wordpress will make it become index.php?pagename=people&username=kureikain Then you createa a new page and make its slug to people! Next you create a new custom page template to display that profile!

Beside, we add a new query var, username to above code! We need to let wordpress knows about it

add_filter('query_vars', 'axcoto_multi_rate_query_vars');
function axcoto_multi_rate_query_vars($public_query_vars) {
    $public_query_vars[] = 'username';
    return $public_query_vars;
}

In your code, to get username, you must call $username = get_query_var('username'); That's all!

0

In my opinion it looks like the only thing you actually need is to change the author base, which this plugin will do for you(basically the same as what MathSmath posted, but in a glorified plugin form).
http://wordpress.org/extend/plugins/custom-author-base/

Your Answer

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