WordPress Tips: How to remove category word from your WordPress url
Ever wanted to be able to finally remove the useless /category/ from your WordPress categories permalinks?
There are various options to remove “Category” Keyword from your WordPress URL’s.
1) .HTACCESS Hack
By default, WordPress category permalinks are displayed that way:
As you can see, the category in the url is pretty useless. Here’s how to remove it:
First backup your .htaccess file. Then, open it and append the following line:
RewriteRule ^category/(.+)$ http://www.xyz.com/$1 [R=301,L]
Once saved, your categories pages will be displayed like this:
2) WordPress Plugin – WP No Category Base
Category word can be easily removed by using WordPress plugin: WP No Category Base
You can download the plugin or directly install in your wordpress from here: http://wordpress.org/extend/plugins/wp-no-category-base/
As the name suggests this plugin will completely remove the mandatory ‘Category Base’ from your category permalinks ( e.g. myblog.com/category/my-category/ to myblog.com/my-category/ ).
The plugin requires no setup or modifying core wordpress files and will not break any links. It will also take care of redirecting your old category links to the new ones.
1. Better and logical permalinks like myblog.com/my-category/ and myblog.com/my-category/my-post/.
2. Simple plugin – barely adds any overhead.
3. Works out of the box – no setup needed.
4. No need to modify wordpress files.
5. Doesn’t require other plugins to work.
6. Compatible with sitemap plugins.
7. Works with multiple sub-categories.
8. Redirects old category permalinks to the new ones (301 redirect, good for SEO).
3) Changing in Category-template.php File
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.
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.
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
$catlink = str_replace(‘%category%’, $category_nicename, $catlink);
$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.
Custom URL Code Snippet
Copy and paste the code below to your custom structure text field and click save.