Remove The Word Category From WordPress URLS

wordpress category removeWordPress shows /category within it’s url link output for categories, this however does nothing to help SEO and more so looks pretty ugly. Removing the category word from wordpress url structure is pretty simple and brianhoff originally wrote a short tutorial covering how to do this. Since v2.6 of wordpress was released however things have change slightly so we thought it would be nice to post an updated version of brians original solution with the correct instructions for v2.6 of wordpress and a lot more detail for beginners.

Understanding What You are About To Do

It’s always worth having a little background information about what your going to acheive by removing the word category from within the wordpress URL structure.

When you create a category in wordpress “Technology” for examples sake with SEO URL re-writing enabled and then browse to that category on your wordpress install the URL structure will look like below.

http://yoursite.com/category/technology/

You will notice the word /category within the URL structure, what this wordpress hack achieves is the removal of the /category word from all URLS. After implementation this then means that the URL structure for categories would now look like below.

http://yoursite.com/technology/

Much cleaner right and it also moves url keywords further to the left.

How To Remove Category From WordPress URL

Open the file /wp-includes/category-template.php in a text editor, we would recommend using PSPad which is a free code editor.

Around line 42 of /wp-includes/category-template.php

FIND

        $catlink = str_replace('%category%', $category_nicename, $catlink);

BELOW ADD

        $catlink = str_replace('category/', '', $catlink);

The code within the category-template.php should now look like the image below, the grayed out areas are the code you should have changed with line 43 being the code you added.

Save the /wp-includes/category-template.php file and upload it to your wordpress site.

Note: The following step is very important or your site will receive 404 errors for categories.

You need to tweak your sites permalink structure from the admin panel, this is done because all posts must have /%category%/ somewhere within the permalink structure. It’s also claimed to be a little better for seo as your urls will now contain more keywords further to the left of the url. This next step is done completely with the admin panel so no more file edits are required.

Goto your wordpress Administration page then Settings / Permalinks. You should be presented with a page like below.

The part we are going to change is Custom Structure so go ahead and select custom structure from the page. We are now going to fill in the text box with our new URL structure code, the image below shows what it looks like and we have included the code for you to copy under the next image.

Custom URL Code Snippet

Copy and paste the code below to your custom structure text field and click save.

/%category%/%postname%-%day%%monthnum%%year%/

What Is The Custom URL Snippet?

The custom code snippet above controls the way url’s are outputted on a wordpress site, below we explain a little about each part of the code.

%category% – This part of the code displays the category name of which the article belongs to.

%postname% – This part of the code is your actual post title.

%day% – Day numer 2 digits

%month% – Month 2 digit

%year% – Year 4 digit

Your resulting article/post url would look like below for category technology and article title “iPhone 3g Launches Around The Globe”

http://yoursite.com/technology/iphone-3g-launches-around-the-world-18082008

You can change any part of the url structure to suit your needs if you remove the %category% code though you will receive 404 category errors. All the tags you can use in wordpress URL structure can be found at the Using Permalinks page over at wordpress.org

You now have a wordpress install without the word /category in the URL structure.

Massive thanks to brianshoff.com for the original code snippet.

If you enjoyed this post, make sure you subscribe to my RSS feed!

Article Details

#

Author: on August 18th, 2008

Category: Wordpress

Tags: , , , , ,

  1. nice post. can you do the same to pligg as well.

    thanks

  2. Lincoln,

    there is type in above code:
    $catlink = str_replace(‘category/’, ”, $catlink);

    is should be:
    $catlink = str_replace(‘%category%’, ”, $catlink);

    thanks

  3. sunilkumar says:

    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.

  4. BK says:

    Thanks. This works well for me in most cases; except in some cases it did not give me the result as expected.

  5. Greyer says:

    The code works well with PARENT categories, but unfortunately it doesn’t work with subcategories. For example if I have a category “Laptops” which is split into several other categories like “Dell”, “Apple”, “HP”, it doesn’t work. When I want to view all posts made in one particular subcategory, I get a “Not Found” error message. Any ideas how to fix that?

  6. Bezza says:

    Great Post,

    Works perfectly, expect that you can no longer use ‘/feed’ behind the category URL, as it no longer works.

    Does anyone have a solution for this problem?

  7. Stewie says:

    Thanks Lincoln,

    I have been working on cleaning up the blog on my site for the past couple of days and your piece of code for removing “category” from the URL was very helpful. Works like a charm :-)

  8. Thanks Lincoln. This is something I have been meaning to do for a while and this post was perfect. It worked like a charm.

  9. Thanks so very much. It works well and I am running wordpress 2.7.1

    It also fixed another problem I was having with a theme I am using too.

    I appreciate it!

  10. Jokes SMS says:

    Hi,
    Previously I was using a plugin called “Top Level Cats” for the same purpose. When I tried to upgrade WP to the latest version, that plugin started giving problem.

    Thanks to your tip, I have now upgraded to WP 2.7.1 and everything is working perfect. Thank you so much.

  1. bloggingzoom.com
  2. Vote for this article at blogengage.com
  3. Quitar la palabra “category” de las urls en nuestro sitio web con wordpress
  4. [Vote 4 Me] Blog Vibrations
  5. Daily Sphinn: Analytics Getting Closer to Omniture, and Sphinn is Dying | UnclePeppers.com
  6. Removing The Word “category” From Your WordPress url Structure : Site Smarty
  7. Remove ‘category’ From URLs In Wordpress - WDBuc Tech Blog

Leave a Reply

You must be logged in to post a comment.