Text Link Ads
Email This Post Email This Post

How to remove category base from permalinks

Wordpress July 7th, 2007

    Visited 55051 times, 2 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);
    NOTE:

    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]

Hi,
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]

Hello

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!
Thanks
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]

Farida,
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]

Thanx.

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]

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

Regards,
Sunil.

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

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

http://www.themadhat.com/blogging/remove-category-base-wordpress/

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+
http://bloggerholic.com/wordpress/how-to-add-trailing-slash-to-a-category-144.htm

MyAvatars 0.2

Leave a Reply


             



Resources

Categories

FREE Newsletter

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

(required)
(required)
 

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
      AuctionAds
      Amazon Associates

Related Articles

Recent Articles

Before you buy windows xp key online buy a new CPU or spend hundreds on upgrades try these three things first. Most computer buy office 2007 online users don't often think of their registry as being a problem when trying to determine what is causing their performance issues. Again this (buying windows operating system) can be done manually through running "msconfig" or download software to do it for you. How to, buy vista license key, make my computer go faster make computer faster speed up PC computer run faster why is my computer so slow. As a buy adobe acrobat mac crucial part of the Windows operating system your computer would be unable to run Windows without a registry. So you buy windows microsoft have to take action fast. It is buy xp activation key always recommended that you try to stay away from free registry cleaners. Let us purchase office 2007 examine what this product does and whether it can fix your slow computer. If you buy dreamweaver uk install and uninstall a lot of software you may have to do it more often. It contains buy microsoft office home and student edition all data to execute commands when running software and hardware. Unless you buy microsoft project standard are a trained computer technician I do not recommend going into the registry and deleting or changing entries as you can end up causing your computer to stop functioning altogether if you are not careful.

Another important buy microsoft office student 2007 point to consider is that the tool is really meant to be used by malware removal experts or at the very least by a trained computer technician who has knowledge of the inner workings of a computer and you'll find a rather large disclaimer about this when you attempt an SDFix download. If there purchase xp downgrade is a lot of clutter in the registry the computer will have to work harder to find it which is why it ends up slowing down so much. A free, purchase xp key, scan is also available you can have a first hand look at the registry errors that are causing this particular problem. Delay means buy xp pro uk cost and cost is one thing that project leaders and owners of the company do not want to happen. It's a buy microsoft word online download tool that has been around for a few years and it is relatively good at removing certain spyware and adware infections but before you go ahead and download SDFix there are some critical facts you need to know about. and in buy adobe photoshop cs4 upgrade order for your computer to be able to run properly and perform tasks efficiently the registry needs to be in tip top shape. There are buy adobe premiere pro essentially three main parts to this virus that must be removed. The registry buy microsoft windows online is an extremely sophisticated and sensitive area. If you buy indesign cs3 are growing tired of your slow PC performance then it could be that it is time to consider checking the Windows registry for obsolete data and invalid entries. But how buy windows license online do you get this nasty virus off your system. Make sure buy photoshop cs2 mac you download software that can perform deep scans and detect files like DLL's and registry entries. Projects cannot purchase adobe photoshop cs3 be avoided especially if you want the company to deliver better services with a faster turn around time. Once these purchase vista upgrade files have been removed your computer performance will be a lot better and it will be able to perform tasks more effectively. A deep purchase windows xp professional license scan will go through the entire registry and remove any files that are not needed. When is buy vista key online the last time you did. But on, buy windows cd key, top of that the top registry cleaners will also optimize and defragment your registry much in the same manner you can defragment your disk drives. You may buy windows xp 2008 also wonder how the best registry cleaners can be quite so cost effective but this is actually quite straightforward. Want to buy windows 2000 professional know how to fix Internet Explorer so that it doesn't freeze up. Heck most purchase microsoft office 2007 license users aren't even sure what the registry is let alone how to fix it. Click below purchase windows operating system for a free scan using the absolute best spyware remover on the market today. In this buy autocad lt article we will explain what a registry cleaner is but also answer the question "what kind of files will a registry cleaner remove. There are buy windows vista student edition many registry cleaners available some you must buy and others are free the question of course is which registry cleaner should you choose. For those buy microsoft office professional 2007 of us working in the computer security industry we knew it was only a matter of time. For most buy visual studio 2008 india people clearing out the registry every six months is a good enough. So if buy windows xp setup cd you feel that your project and your team members are running in circles consider document version control software. Once these buy adobe acrobat cheap files have been removed your computer performance will be a lot better and it will be able to perform tasks more effectively. What makes buy adobe photoshop for vista spyware and viruses different.