
Email This Post
How to remove category base from permalinks
Wordpress July 7th, 2007
Visited 55051 times, 2 so far todayLooking 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:
- Go to your wp-includes folder.
- find the template file called “category-template.php” and open the file in any text editor.
- Find the follwing line $catlink = $wp_rewrite->get_category_permastruct();
You will see this code two lines below function get_category_link($category_id) { - 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. - 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:
- Go to your wp-includes folder.
- find the template file called “category-template.php” and open the file in any text editor.
- In this file find the following function, function get_category_link($category_id) {
- Find the following line inside this function $catlink = get_option(’home’) . user_trailingslashit($catlink, ‘category’);
- Below it add the following line $catlink = str_replace(’/category’, ”, $catlink);
- 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
[ # 31 ] Comment from Charlie [July 12, 2007, 8:40 pm]
[ # 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.
[ # 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.
[ # 37 ] Comment from Farida [July 15, 2007, 10:16 am]
[ # 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
[ # 55 ] Comment from Farida [July 18, 2007, 9:32 am]
[ # 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 : /
[ # 57 ] Comment from Farida [July 20, 2007, 10:02 am]
[ # 90 ] Comment from Charbax [August 13, 2007, 7:12 am]
[ # 760 ] Pingback from Блог unsimilar’а » Blog Archive » О геноциде префикса “category” [October 22, 2007, 11:34 pm]
[ # 2591 ] Comment from baa [March 31, 2008, 2:34 am]
[ # 3193 ] Comment from purose.cn [May 6, 2008, 7:44 pm]
[ # 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?
[ # 3759 ] Comment from Brian [June 10, 2008, 9:37 pm]
[ # 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!
[ # 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.
[ # 9483 ] Comment from Greyer [October 6, 2008, 11:29 pm]
[ # 10034 ] Comment from Farida [October 14, 2008, 9:46 am]
[ # 10999 ] Comment from fritz [October 25, 2008, 11:48 pm]
[ # 11385 ] Comment from Dixlan [October 30, 2008, 5:38 am]
[ # 11434 ] Comment from Mike [October 30, 2008, 8:04 pm]
[ # 11440 ] Comment from SEO Binh Nguyen [October 30, 2008, 9:37 pm]
[ # 11443 ] Comment from SEO Binh Nguyen [October 30, 2008, 9:49 pm]
[ # 11504 ] Comment from Yazerty [October 31, 2008, 4:55 pm]
[ # 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/
[ # 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


[ # 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);