If you're new here, you must subscribe to my RSS feed, or I will hunt you down. Thanks for visiting!
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.






















{ 26 comments… read them below or add one }
This is going to be really helpful for me, thanks for the extra effort. It would be great if someone could work it into a plug-in. Anyone? ::crickets::
makes me wanna play guitar hero.
Thx Themadhat this creepy category base is much pain for me now, i’ll try your method.
I tried it, and it did remove the category from the url, but I still got a 404 error when i went to the category, so no go for me. Thanks though
@Vahid - yea, it could be conflicting with another plugin or something already in your .htaccess file. Either could easily be the case.
That’s why this is such a pain in the ass, too many variables to work with inside Wordpress.
Jajaja thanks for this post I tried this on my blog and what would you know i got the categories removed. Nice ending for a post
@Edgar. Good deal, glad it’s working for some.
After reading the above post, being a heavy duty user of wordpress myself, and even knowing Matt Mulenweg and Doncha the original developers, it is my carefully stated opinion that putting the picture of the hot chick playing whatever she was playing was a good idea.
dk
That’s what I was getting at…
Thanks for sharing your effort. I’m learning wordress and would like to read more posts in future.
the WP theme i’m using doesn’t have the
if ( isset($error) )code in wp-includes/classes.php.$this->query_vars['error'] = $error;
any suggestions in that instance ..?
@craig - you’re theme shouldn’t make any difference. Themes don’t modify files inside wp-includes/
What version of WP are you running?
I tried many solutions before. Now I try yours, and still… my sub category will be 404 when I use this post permalink: /%category%/%postname%/
I guess you don’t have time for this anymore. So just take it as a sigh. If you do have a solution, please email me. I will really appreciate. Thanks.
I didn’t test it on sub categories. Stay tuned, the plugin might address that issue.
Hello
At last I got it. Thank you so much
This is what exactly I am suffering with. Good Post.
Regards
Sankar Datti
Thanks for this tweak. I’m thinking on switching to wordpress for my other sites but I’m still taking notes on some things I don’t like.
Thanks for the info. i’ll try your method out…
im really interested in sorting the subcategories out
the “fix” works like a charm for main categories
but all subcats bring a 404 error
madhat, pls enlighten us with another fix for subcats
ahoy ye m8ies
@WebDuDe - A plugin for this is coming soon, I’ll see if we can get this addressed. I don’t use subcats so I didn’t put it in, but the plugin hopefully can do this. It’s a bit more complicated than it looks.
Post was interesting to read! I just want to try it out once.
Why not just use the custom structure in wordpress admin?
Because that doesn’t work. The way the hooks are written forces “category” on any category pages before the actual category. This gives you the proper site architecture.
Thx Themadhat this creepy category base is much pain for me now, i’ll try your method.
Hey Dude !
This is really very useful information. Keep it sharing.
I followed the instructions and it worked for my website, thank you
Haha good stuff thanks!