1

I've tried a bunch of things but cannot find a solution that works.

I want my site to have the structure:

mysite.com/ = homepage
mysite.com/blogs/ = blog archive
mysite.com/blogs/year/ = blog archive (in a specific year)
mysite.com/blogs/year/month/ = blog archive (in a specific month)
mysite.com/blogs/year/month/postname = blog post
mysite.com/authors/ = authors archive
mysite.com/authors/nicename = author profile
mysite.com/customposttype/ = custom post type archive
mysite.com/customposttype/postname = custom post type post

Currently, with /blogs/%year%/%month%/%postname%/ set as the permalink structure, everything works correctly except the authors part. It forces it to mysite.com/blogs/authors/ and mysite.com/blogs/authors/nicename, which is not desireable, since most authors will be making custom post types and not blogs.

Some posts I checked here but without the right answer:

How to properly prefix blog post URL's

Permalinks Question: Adding a prefix ONLY in front of the posts

Possible to change the URL for the regular post type without affecting the URL of other custom post types?

1
  • Also I realize that the structure of /blogs/%postname%/ and blogs/%year%/%month%/%postname% are different in the title and content of the post, but those aren't the issue (I just typed it over a long period of time and didn't stay consistent).
    – ZachM
    Jun 20, 2012 at 20:56

1 Answer 1

4

You can set the author base independently by manipulating the $wp_rewrite global:

function wpa55976_author_base() {
    global $wp_rewrite;
    $wp_rewrite->author_base = 'authors';
    $wp_rewrite->author_structure = '/' . $wp_rewrite->author_base . '/%author%';

    // EDIT - rewrite rule to force author urls to resolve:
    add_rewrite_rule('authors/([^/]+)/?$', 'index.php?author_name=$matches[1]', 'top');

}
add_action( 'init', 'wpa55976_author_base' );

Make sure to visit your permalinks page to flush rewrites after you add this.

The one thing you won't get is mysite.com/authors/ = authors archive, as WordPress doesn't provide this page by default, though you may be able to create an authors page and use a custom template, or add a rewrite rule to handle it.

8
  • Thanks! This works to change the links to all point to mysite.com/authors/name but that link 404s every time, however, mysite.com/blog/author/name still displays the correct information. Edit: and I just tried going to Settings -> Permalinks and saving to refresh the Permalinks. No dice :-(
    – ZachM
    Jun 21, 2012 at 13:43
  • @ZachM - did you put it in the theme's functions.php file? the rewrite can't be present if the old author URLs still work. I've just tried it on a brand new 3.4 install with TwentyEleven theme and it's working here, if you could give that try and verify there's not otherwise a theme or plugin conflict.
    – Milo
    Jun 21, 2012 at 13:59
  • I had it in my plugin. I'll try switching it to functions.php.
    – ZachM
    Jun 21, 2012 at 14:31
  • I had the Edit Author Slug plugin activated from an earlier attempt, which was conflicting. Once I turn it off, it works! Thanks a million!
    – ZachM
    Jun 21, 2012 at 14:53
  • Actually it was working for a bit, then I went and added a custom taxonomy for something seemingly unrelated, and it broke again. I have no other modifications of the global $wp_rewrite variable in either the theme or any active plugin.
    – ZachM
    Jun 21, 2012 at 15:53

Your Answer

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

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