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('/remove_the_word_category_from_wordpress_urls_18082008/category/index.html', '', $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 our RSS feed!

Article Details

#

Author: Lincoln on August 18th, 2008

Category: Wordpress

Tags: , , , , ,

  1. Lincoln says:

    Happy this method worked for you :)

  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