Change or remove the "Category" from your permalinks on a wordpress blog

My friend Frank over at YouShouldKnow.com just gave me a good tip on how to remove the optional "Category" in your category URL's on a WordPress blog.

Normally the categories would look like this:
http://www.clausheinrich.com/category/web-directory/

with the change it will become:
http://www.clausheinrich.com/web-directory/

Find the file wp-includes/classes.php and about halfway down you can change the settings.
To remove the category like above do this:

$this->category_structure = $this->front . 'category/';

change it into this:

$this->category_structure = $this->front;

Update:
In the WordPress 2.1 branch you will find the code in wp-includes/rewrite.php
Thanks to Caio Proiete for informing

WordPress Version 2.3.x branch:
Delete this:
$this->category_structure = $this->front . 'category/'; else

WordPress Version 2.5.x branch:
I have not tried this personally, but reading from comments it is should be possible to now use the Base Category feature to disable the "category" directory.
Brad mentions in comment #27:
Adding the /. in Settings - Permalinks -Category Base field works fine in 2.5.
Where are ppl seeing the /. in the URL? (e.g. www .example.com/./foo/)
Im having no problems with it.

So feel free to test this out, and any reports back are appreciated.

UPDATED INFO - IMPORTANT: I noticed in my logs that this post is still getting traffic from people looking to change the category/ prefix.
I recommend a good plugin to handle this now:
Top Level Categories.

Related Posts

Commentary

Leave a response »

  1. 1. February 13th, 2007

    Great idea, but that code doesn’t seem to be in classes.php on WordPress 2.1

  2. 2. February 13th, 2007

    Hmm, interesting. One more reason to wait with my 2.1 update then :)

  3. 3. February 23rd, 2007

    The hack is the same, only the location has changed. You’ll find this code in rewrite.php

    Thanks,
    Caio Proiete
    http://www.pdaexpert.net

  4. 4. February 24th, 2007

    cheers Caio

  5. 5. April 8th, 2007

    Hmm. In the WP Admin screen Options -> Permalinks. Can’t you just enter ‘/.’ into the Category Base feild?

    No code hacking needed.

    I just verified this from WP 2.0.2 thru 2.1.3. Seems to work.

  6. 6. April 8th, 2007

    That was actually the first thing I tried back in 2.06. Nothing seemed to happend when entering / in the field. After save the /category/ was still active.

    It would seem as the right way to do it, so code hacks shouldn’t be done.
    Can anyone else verify it works through WP Admin. Might just be something wrong with my build here as I have alot of customization

  7. 7. August 18th, 2007

    Thanks, is it posible to remove the parent category too?

  8. 8. August 18th, 2007

    You need to give me some more specific info on which parent link you are refering to. Menu or on posts permalinks? If it is in the posts, it might be because you have set permalinks to something like /%category%/%post-id%/ under your options in wp-admin. You could remove the %category%/ if that is the case

  9. 9. August 26th, 2007

    RE: adding the ‘/.’ to Category Base.

    Make sure you have the period ‘ . ‘ after the forward slash.

    I just tested it on a 2.2.2 build and it works fine :)

  10. 10. August 26th, 2007

    thanks for info Jackson Lin

  11. 11. August 28th, 2007

    Just wanted to add onto my comment…

    Setting the category base to ‘/.’ does seem to work (i.e. when you hover over the category names or when you click it, there is no ‘category’ text)

    But…

    If you view the html source, I noticed that it added a period ‘ . ‘ in the URL (e.g. http://www.example.com/./foo/)

    I’m not sure if that will affect SEO at all so in the end I decided to take the plunge and edit the rewrite.php file.

    Thanks for the article, Claus!

  12. 12. August 28th, 2007

    Ahh, good catch Jackson. I didnt get around to test it yet.
    But I agree.. If it adds the period to the url it wont be very seo-wise..
    Editing the rewrite.php file is pretty easy and works splendid

  13. 13. September 11th, 2007

    it looks like this
    http://www.BLOGURL.com//.CATEGORYNAME/

    //. ??? seems funny :(

    webo
  14. 14. September 11th, 2007

    Sure you have edited the file correctly webo? Would be the most common mistake.
    be 100% sure you replace:

    $this->front . ‘category/’;

    with

    $this->front;

    Also try go to Options -> Permalinks and type / in category base and save.

  15. 15. October 3rd, 2007

    Is this the same for 2.3 ??

    Paul
  16. 16. November 3rd, 2007

    >Paul: I didnt update yet, but will let you know when I get it done, if noone beats me to it :)

  17. 17. December 28th, 2007

    It doesn’t work in W 2.3.1. Links are changing but when you click on it E404 appears.

    Any solution?

    scooly
  18. 18. December 28th, 2007

    I still haven’t got around to update to version 2.3.x
    Afraid I cant help until I get the time to upgrade

  19. 19. January 10th, 2008

    It didn’t work for me in 2.3.2. Instead, I just changed the logic in the same file by deleting this:

    $this->category_structure = $this->front . ‘category/’; else

    The omission obviously means problem if you later want to specify a category base, so you should keep this change in mind.

    hello
  20. 20. January 23rd, 2008

    This is a neat hack, but doesn’t this make updating a pain? Is there a way to roll this into a plugin?

  21. 21. January 23rd, 2008

    everytime you change the core files it will be a little pain to “remember” what you did when updating next time.
    Would be nice to automate this in a module/plugin, but I dont know of any.
    Personally I got a little notebook with “things to remember when installing/updating WordPress” :p

  22. 22. March 14th, 2008

    hi,

    I tried and made the changes, and the category page is working perfectly, but getting problems with the archive area, when i click a archive link, its directing me to a 404 page, any solution?

    Krishna

    Krishna
  23. 23. March 24th, 2008

    Would it be possible to make the code change in functions.php? That way it would be theme specific and endure WP upgrades.

    Drew
  24. 24. March 30th, 2008

    Just adding infos, it doesn’t work in 2.3.3 either.

  25. 25. April 7th, 2008

    Just tried this on 2.5, no joy, anybody tried giving it a go on the new version yet and got some results, cheers.

  26. 26. April 19th, 2008

    Hey. This may be a bit late for 2.3.2, but did anyone ever find a fix for this – or had the issue been fixed for WP 2.5?

    Thanks

  27. 27. April 27th, 2008

    Adding the /. in Settings – Permalinks -Category Base field works fine in 2.5.

    Where are ppl seeing the /. in the URL? (e.g. www .example.com/./foo/)

    I’m having no problems with it.

    Brad
  28. 28. April 27th, 2008

    Hi Brad, well that could be very good news if the category base works like this now.
    Do you have a site where I could see this in action?

  29. 29. April 28th, 2008

    Claus – this is my test site: http://javajenius.com

    It’s upgraded to 2.5.1 and so far no issues …

    Brad
  30. 30. April 29th, 2008

    Ok it looks like the only problem I’m having is I’m getting a 404 Page not found when I try to page thru results on the category pages. Of course it works when I remove the /. in the category base field.

    Looks like a WordPress bug.

  31. 31. May 1st, 2008

    Thanks for the updates Brad.. Please keep them comming if you find a solution.
    I will update my post with your findings

  32. 32. November 4th, 2008

    I can’t get /. to work either. I get errors when I try click on any category. It probably doesn’t help that I am just using the following permalink structure: domain.com/postname

    Anyone got any bright ideas on how to solve this problem of removing “category” while using just /%postname%/ ?

    Kevin
  33. 33. November 14th, 2008

    I needed this for changing the breadcrumb path and it worked like a charm in 2.7 b2, just by setting the caregory base to /.

    and by the way: After saving, WP changes it to just the .

    Tibor
  34. 34. March 17th, 2009

    Adding the /. in the Permalinks Category setting will work in 2.7 and up when I tested it. Very easy! Thanks.

  35. 35. April 1st, 2009
    iDope

Trackbacks

  1. [...] you as me like to remove the /category/ from your permalinks, feel free to jump to my post about it Experience any problems? Report it to [...]

    Problems with my permalinks « My Personal Webmaster Blog

Leave a comment, a trackback from your own site or subscribe to an RSS feed for this entry. Trackback URL for this entry Comments feed for this entry

Leave a response

Leave a URL

Preview
Dansk blog Engelsk blog
Twitter Claus Heinrich