
This might have been the most annoying thing I’ve had to do in a while. As you’re probably well aware, the pesky “category” level that shows up in your category page URL’s was practically impossible to get the hell off. There were several plugins sitting out there and none of them worked quite right. All the ones I found worked to some degree, but there was always some problem that I didn’t like.
You’ve got the Category Base Killer plugin which seemed to work fine at first, but pagination wouldn’t work and apparently there is a problem with having a subcategory or a category with a parent.
There is the Top Level Category plugin, which worked only if you added an extension to your post names. You’d end up with funky looking URLs like /category/post.html/ and that would require redirecting all of your posts. And again pagination didn’t work.
There were a few more custom coding solutions I came across that blew up my blog.
Here is what I did and I’ve fooled around with mine enough to where I think it works right. First some caveats:
1) I’m using the Thesis Wordpress Theme (great theme by the way). I didn’t change any code inside the theme so this shouldn’t matter.
2) I don’t use subcategories or parent categories so I don’t know if that works or not. I also don’t use multiple categories, but I don’t think that matters. I believe it just uses the first one anyway.
3) My permalink structure is set at /%category%/%postname%/ - if yours is different, you’ll probably need to tweak it.
4) This isn’t a plugin (yet, I might get around to doing that but I have never written a plugin before and I wanted to get this out now). This means when you upgrade Wordpress, you have to insert the code again. (Tip: I comment in // $$$ Custom code // where I put in my own stuff so it’s easy to find and fix when Wordpress updates)
So, here is the solution:
1) In wp-includes/category-template.php search for the following line of code:
$catlink = get_option('home') . user_trailingslashit($catlink, 'category');
Just below that, insert the following:
$catlink = str_replace('/category', "", $catlink);
2) In wp-includes/classes.php search for the following block of code:
if ( isset($error) )
$this->query_vars['error'] = $error;
Just below that, insert the following:
if (@$this->query_vars["name"] == "page")
{
$tmp_ar = $this->query_vars;
$this->query_vars = array();
$this->query_vars["paged"] = str_replace("/", "", $tmp_ar["page"]);
$this->query_vars["category_name"] = $tmp_ar["category_name"];
}
3) Finally, in your .htacces file, add the following to redirect your old /category/ URLs to your new ones (if your blog doesn’t reside in the root, you’ll have to tweak it):
RewriteRule ^category/(.+)$ http://www.domain.com/$1 [R=301,L]
There you have it. I don’t guarantee this will work for you, and if it doesn’t, well bite me because I tried. And just to make this post more interesting, here is a random hot chick with Guitar Hero.