Claus Heinrich

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

My friend Frank over at YouShouldKnow 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:
https://www.clausheinrich.com/category/web-directory/

with the change it will become:

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.

36 Comments

  1. 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.

  2. 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

  3. 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

  4. 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 🙂

  5. 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!

  6. 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

  7. 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.

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

    Any solution?

  9. 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.

  10. 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

  11. 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

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

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

  14. 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

  15. 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.

  16. 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.

  17. 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%/ ?

  18. 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 .

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

Leave a Comment