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

    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!
    3 Votes | Average: 5 out of 53 Votes | Average: 5 out of 53 Votes | Average: 5 out of 53 Votes | Average: 5 out of 53 Votes | Average: 5 out of 5
    Avg. Rating: 5 - Total Votes: 3
    Loading ... Loading ...



8 Responses to “Removing the Dreaded Wordpress “Category” Forever!”

  1. Caio Proiete says:

    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

  2. irawan says:

    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

  3. Brian says:

    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.

  4. Mike says:

    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.

  5. Brian says:

    Hey Mike. Glad it helped. I too lost a few years of my life on this one.

  6. farida says:

    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

  7. Блог unsimilar’а » Blog Archive » О геноциде префикса “category” says:

    […] Кому интересно посушить мозги, вот ссылочки: 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? […]

  8. Category Base in Wordpress deaktivieren - WhiteSide SEO says:

    […] 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. […]

Leave a Comment

Creative Commons License

This work is licensed under a
Creative Commons Attribution 2.5 License.
34 queries. 0.444 seconds.