Removing the Dreaded Wordpress “Category” Forever!
Who thought it could be so difficult to remove 8 little letters?!?
I recently turned my back on Drupal and installed Wordpress 2.0.5. It isn’t perfect, but it’s much easier to skin (to me anyway).
One of Wordpress’s idiosyncrasies is it appends what it calls a “category base” to each of your posts. So when you want your URL to look like this:
http://www.myblog.com/category_name/post_title.htm
It makes it look like this:
http://www.myblog.com/category/category_name/post_title.htm
Annoying!
Yes, you can change what this word is under options > permalinks area of the admin. But what if you want to get rid of it all together?
After a little digging, I discovered the answer! A simple one line hack that solves my category base woes forever!
On line 36 of the wp-includes/template-functions-category.php file, you’ll see the code:
$catlink = str_replace(’%category%’, $category_nicename, $catlink);
To remove “category” from the URL, simply add this line under it:
$catlink = str_replace(’category/’, ‘’, $catlink);
That’s it! Try it out!
-
UPDATE
I recently created a plugin that takes care of all of this for you. It will come in handy when you go to update WordPress.
-
UPDATE
After some testing, I found that you must have "%category%" in your permalink structure for this to work. Otherwise, your category pages will break.
Help Me Improve!
- The only way for my posts to get better is to get your opinion! So help me out, and rate this one! Thanks!
Related Posts
Category Base Removal Plugin
The Category Base Killer Plugin does exactly what it says. It removes the "category/" text from your WordPress URL string. ...
Columbia PA’s “Perfect Settings” Gets a New Face
It seems that everyone I know is either married or is getting married. I myself am on the band wagon being engaged to my fia...
More Than I Could Chew
After successfully creating a custom theme for my Wordpress front end, I thought it’d be a neat idea to theme the back end ...






February 23rd, 2007 at 11:12 am
Hi Brian,
Nice hack! Thanks for sharing.
Although your approach works fine, I guess it would be better not to do a string replace on the category link string, but instead, modify the function that actually build permalink structure. A few lines above your modification, you can see a call to get_category_permastruct() that is the function who brings us the annoying “category/” on the link.
Here is my version of the same hack:
On line 371 of the wp-includes/rewrite.php file, you’ll see the code:
$this->category_structure = $this->front . ‘category/’;
Now just remove the “category” from the string, and the code should look like:
$this->category_structure = $this->front . ‘/’;
Done… The same result, but a bit more elegant.
Caio Proiete
www.pdaexpert.net
March 26th, 2007 at 9:22 am
Hi Brian,
Thank You very much for the shared tricks, I had used Caio Proiete’s ‘hack’ before, it worked ! But after I restart my laptop (I tested first in localhost), it said 404 for all pages .. so sad.
Miraculously .. I found this tips..
again thank you, I’ll touch you after my blog is up
May 8th, 2007 at 2:20 pm
UPDATE
I used the method described by Caio Proiete and was having some issues with links inside of the various categories returning a 404 error. I then went back to the original method and it worked.
Strange. I don’t know why it worked and the other way didn’t, but I thought it worth mentioning.
June 19th, 2007 at 8:46 am
My God in heaven! I’m practically bald from pulling my hair out on this one. Thank you for the great solution. Like others, Caio’s approach didn’t work for me, but this works like a charm.
June 28th, 2007 at 11:33 am
Hey Mike. Glad it helped. I too lost a few years of my life on this one.
July 7th, 2007 at 6:13 am
Hi
see this 5 step tutorial that tells you how to remove category base form permalinks. This is only for wordpress 2.0+ the only difference is that it uses category-template.php.
http://bloggerholic.com/wordpress/how-to-remove-category-base-from-permalinks-45.htm
October 22nd, 2007 at 5:17 pm
[…] Кому интересно посушить мозги, вот ссылочки: Change or remove the “Category” from your permalinks on a wordpress blog How to remove category base from permalinks Removing the Dreaded Wordpress “Category” Forever! WordPress Ideas: Remove ‘Category Base’ From Permalinks WordPress Support: how could i remove word “category” from urls? […]
May 19th, 2008 at 9:06 am
[…] Brian Shoff schlägt zur Entfernung der Category Base in einem anderen Artikel noch einen Eingriff in den Code vor und überall sind Hacks im Einsatz. […]