Text Link Ads

How to remove category base from permalinks

Wordpress July 7th, 2007

    Visited 83006 times, 1 so far today

Looking through the wordpress forums I saw a large number of people wanting to know how to remove ‘category base’ from permalinks. For example http://bloggerholic.com/category/wordpress/ 

I found the solution and it’s easy! This is only for WordPress 2.0+
All you need to do is the following:

  1. Go to your wp-includes folder.
  2. find the template file called “category-template.php” and open the file in any text editor.
  3. Find the follwing line $catlink = $wp_rewrite->get_category_permastruct();
    You will see this code two lines below function get_category_link($category_id) {
  4. Below it add the following line $catlink = str_replace(‘/category’, ”, $catlink);

    Due to the font the code has changed, Please make a note to change the curly quotes into standard text quotes.
  5. Save the file and upload “category-template.php” in wp_includes folder.

Update: For those using wordpress version 2.61 and 2.62 the above will not work so you will need to do the following:

  1. Go to your wp-includes folder.
  2. find the template file called “category-template.php” and open the file in any text editor.
  3. In this file find the following function, function get_category_link($category_id) {
  4. Find the following line inside this function  $catlink = get_option(‘home’) . user_trailingslashit($catlink, ‘category’);
  5. Below it add the following line $catlink = str_replace(’/category’, ”, $catlink);
  6. Save the file and upload “category-template.php” in wp_includes folder.

That’s it your done! :)

NOTE: Make sure you don’t name your page name the same as category name.

Go back to:WordPress for Dummies

This book “WordPress for Dummies” provides you with everything you need to get up and running with WordPress. The book covers blogging basics, choosing a hosting solution or setting up a host, developing blog content, syndicating blog posts with RSS, launching a specialized blog (including podcasting, photoblogging, mobile blogging, and videoblogging), and even earning revenue.
It Includes help on every aspect of installing and using WordPress, illustrations from real-world WordPress blogs, step-by-step tutorials on key topics, and insights from bloggers who have used WordPress

Read the Comments

[ # 28 ] Comment from Kris Rzepkowski [July 11, 2007, 7:14 pm]

THANKS for this. I don’t really know php, so excuse me if te beow doesn’t make complete sense.

In order to make it work, I needed to do a couple of things…

1. I needed to copy and paste your code from my browser into notepad and change the curly quotes into standard text quotes. The way you have your font formatted doesn’t work when copying and pasting code

2. I found that the code errored out until I added a second quote in front of the second argument in the array, so I ended up with the following as the inserted line, and it worked:

$catlink = str_replace(‘/category’, “”, $catlink);

MyAvatars 0.2

[ # 31 ] Comment from Charlie [July 12, 2007, 8:40 pm]

Hi there

I managed to get this working with help from the extra instructions from Kris above.

However this dosen’t work for sub-categories as I just get a 404

MyAvatars 0.2

[ # 32 ] Comment from Farida [July 13, 2007, 4:40 am]

Hi Charlie I created a sub-category on this site to test it and it worked fine for me. If you have copied the code from Kris (above) do not add the second quote. It should work by just adding this code $catlink = str_replace(‘/category’, ”, $catlink);
Otherwise it could be a problem with the way your permalinks are set up.
Try that and let me know if you have problems.

MyAvatars 0.2

[ # 36 ] Comment from Charlie [July 14, 2007, 10:49 pm]


I retried you code as you suggested and got this error which broke the page:

Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /homepages/18/d96255924/htdocs/casino-heaven.eu/wp-includes/category-template.php on line 56

I had actually tried your tip before Kris posted his improvements and had the same problem – at which point I gave up.

I have to admit that there could be any number of conflicts with exiting plugins, which may be making the difference between this working or not.

I have got Filipe Fortes’s plugin Top Level Categories working which will do the job so I might just stick with that.

MyAvatars 0.2

[ # 37 ] Comment from Farida [July 15, 2007, 10:16 am]

Hmm…what version of wordpress are you using? This will only work for the latest version – WordPress 2.0+

MyAvatars 0.2

[ # 54 ] Comment from Aleksey [July 17, 2007, 7:18 am]

Hi Farida,
Could you please to clear up the mystery of how to make links for tags from tag cloud like “/tag/tag_name” or even “/tag_name” instead of “/index.php?tag=new”. I see your tag links are fine tuned and seo friendly… but mine, hrrrr.
No matter what I did, wp shows 404 error…

Will be appreciate for help!
PS setting up utw options brings the same results – 404 – page not found

MyAvatars 0.2

[ # 55 ] Comment from Farida [July 18, 2007, 9:32 am]

Hi Aleksey
There is a setting in Options->Tags to “use url rewriting for local tag urls (/tag/tag instead of index.php?tag=tag)” (top of the page under configuration) – make sure this is checked. Also make sure the base url underneath is /tag/

Let me know if you need any more help

MyAvatars 0.2

[ # 56 ] Comment from Aleksey [July 18, 2007, 11:49 am]

the Options->Tags is not working for me and for many other users who installed the latest version of wp (2.2.1 I think). There lots of discussion around this problem, but nobody can find out a panacea.

People say it’s about some type of conflict between wp and utw code.

That is the exact what I say. Funny thing, but when you turn off the rewrite rule for categories and permalinks (fancy urls I think or smth like that) in wp options and that activate “use url rewriting for local tag urls …” the UTW rewrite function becomes working properly. But as soon as I turn on fancy url back utw stops working again.

I’m so confused : /

MyAvatars 0.2

[ # 57 ] Comment from Farida [July 20, 2007, 10:02 am]

Ok, the version i’m using is 2.1.2 that’s probaly why mine is working.

MyAvatars 0.2

[ # 90 ] Comment from Charbax [August 13, 2007, 7:12 am]

So does it not work on the latest version of WordPress which is 2.2?

I tried to follow the instructions and I got problems when navigating to the /page/2/ it showing a 404 error.

MyAvatars 0.2

[ # 760 ] Pingback from Блог unsimilar’а » Blog Archive » О геноциде префикса “category” [October 22, 2007, 11:34 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 [...]

MyAvatars 0.2

[ # 2591 ] Comment from baa [March 31, 2008, 2:34 am]


I have WP 2.5.
I did what u said and it worked.

in the folder wp-includes, in the file category-template.php,
I wrote on the line 28:
$catlink = str_replace(‘/category’, ”, $catlink);

MyAvatars 0.2

[ # 3193 ] Comment from purose.cn [May 6, 2008, 7:44 pm]

The Plugin is very good!!
Thand you!

MyAvatars 0.2

[ # 3442 ] Comment from Safira [May 16, 2008, 12:34 pm]

hi Farida!
Thank you very much for support!
But i have a problem on my blog after removing “category” in my url’s.
The same problem like Charbax (above) told.
I am having problem when i am navigating to the category_name/page/2/ and im getting a 404 error
You can see it here: http://www.firanet.nl/kapsels-haarmode/page/2/
Do you have any idea how i can solve this problem?

MyAvatars 0.2

[ # 3759 ] Comment from Brian [June 10, 2008, 9:37 pm]

Hi Safira I have the same problem as you,
I can see you fixed your problem! How did you do this?

MyAvatars 0.2

[ # 5497 ] Comment from Christopher Keys [August 3, 2008, 4:36 pm]

Ok figured it out!

Using WP 2.6

1. Using the following code in category-template.php:

function get_category_link($category_id) {
global $wp_rewrite;
$catlink = $wp_rewrite->get_category_permastruct();
$catlink = str_replace(‘/category’,””, $catlink);

2. Then was getting 404s for all category archive pages, so then went to admin panel / settings / permalinks / in custom structure added this: /%category%/%postname%-%post_id%.htm

Now it is beautiful! Check it out at http://www.carbonoffsetsdaily.com.

Thanks for the great code!

MyAvatars 0.2

[ # 8721 ] Comment from sunilkumar [September 26, 2008, 8:17 am]

It worked for me when i did as you said
but i am getting the links as http://www.localsadda.com/softwares
The last slash is not coming.
How can i get the ‘/’ at the end of the category i.e., after word softwares in the above link.


MyAvatars 0.2

[ # 9483 ] Comment from Greyer [October 6, 2008, 11:29 pm]

I tried your code and it does work, but only for PARENT categories. I am using a

-subcategory 1
-subcategory 2

and unfortunately it doesn’t work for the subcategories :( Any ideas?

MyAvatars 0.2

[ # 10034 ] Comment from Farida [October 14, 2008, 9:46 am]

Hi Greyer

What version of wordpress are you using? The code won’t work i’ve found with the latest versions of wordpress. Check the update on the post above and try that instead. It will work with subcategory’s as well.

MyAvatars 0.2

[ # 10999 ] Comment from fritz [October 25, 2008, 11:48 pm]

Man, all that does is changing the category links in your templates. When you click on those links, you get a ‘page not found’ if the category is nested.

Unless you want to use just non-nested categories, there’s no trivial workaround for this.

MyAvatars 0.2

[ # 11385 ] Comment from Dixlan [October 30, 2008, 5:38 am]

WordPress can remove category base from permalinks :

Simply use : ” /. ” in category’s permalinks with no “” when you configure it.

MyAvatars 0.2

[ # 11434 ] Comment from Mike [October 30, 2008, 8:04 pm]

I’ve got it working fine with this:

$catlink = str_replace(‘/category’, “”, $catlink);

However, it 404′s on any page 2 archives (domain.com/news/page/2/)

Any idea for a fix there?

MyAvatars 0.2

[ # 11440 ] Comment from SEO Binh Nguyen [October 30, 2008, 9:37 pm]

Thank you. Based on your code I made a plugin to do the job. It work great.

MyAvatars 0.2

[ # 11443 ] Comment from SEO Binh Nguyen [October 30, 2008, 9:49 pm]

I notice you have .htm suffix on your post slug without trailing slash (/), then how could u still have the category slug with trailing slash? Please, I need to know because this is exactly what I wanted.

MyAvatars 0.2

[ # 11504 ] Comment from Yazerty [October 31, 2008, 4:55 pm]

This is a tip : just add “/.” (without “”) in admin -> permalinks -> cat. prefix
This delete “category/” :-) !!!

MyAvatars 0.2

[ # 11515 ] Comment from Aaron [October 31, 2008, 10:36 pm]

I fixed the pagination problem. See here for my solution, it’s fairly easy.


MyAvatars 0.2

[ # 12982 ] Comment from Farida [November 18, 2008, 2:45 am]

Regarding adding trailing slash, see this 5 step tutorial that tells you how to add trailing slash to a category. Please note this is only for wordpress 2.6+

MyAvatars 0.2



FREE Newsletter

Sign up TODAY and get FREE Tips every Week on Making Money on the Internet 

Recommended Book


Tag Cloud

Wordpress Blog Marketing Blogging Tips Blogging Tools and Services Advertising VoIP Blogging for Money Search Engine Optimization Adsense General

Recommended Money Makers

      Text Link Ads
      Blog Mastermind Affiliates
      Amazon Associates

Related Articles

Post-Plugin Library missing

Recent Articles