How to Remove the Word “Category” From WordPress URLs

How to Remove the Word “Category” From WordPress URLs

WordPress has a very specific directory structure for its category archives. By default, if you have a category called “technology” and you visit the category page, the URL will look something like this www.yourwebsite.com/category/technology. You can see a screenshot on my test website below:

category keyword

Similarly if you have nested categories, they will be appended to their parent. There is a setting in the administration area of WordPress that allows you to change the word “category” to something else like “topic”. But there’s no clear method on removing the placeholder altogether.

In this article, I’m going to look at three ways to accomplish this. Because of the complex interactions between URLs and how WordPress functions, you might need to try more than one of them before you find one that works properly with your theme and your WordPress installation.

Using the “.” For the Category Base

In the first method, we’re going to use the default WordPress interface. To access this, open up your administration dashboard and go to “Settings->Permalinks” on the left-hand side as shown here:

permalinks location

This will open up the permalinks interface which controls the naming scheme of WordPress URLs. There are two steps to perform here. First, scroll down to the “Custom Structure” radio button, select it, and type the following into the text box:

/%category%/%postname%.html/

Next under the “Optional” section, find the first label called “Category base” and type in a single dot (.) .You can see what this looks like in the screenshot here:

dot in category base

This will have the effect of removing any category slug regardless of the name. If you don’t want to change the custom structure, try the next method instead. Here’s how my website URL looks after the change:

category base removed

Rewriting the URL in functions.php

If you don’t know how to add code snippets in WordPress, you need to read my earlier tutorial on how to accomplish this. You need it in order to use the code below.

Before you implement this technique however, make sure that you go to your permalinks settings and remove any custom “Category Base” that you may have created. This is because the code below is going to specifically search for the word “category”. Navigate to your functions.php file under “Appearance->Editor” from your WordPress dashboard and paste the following code at the bottom before the closing ?> PHP tag.

function remove_category( $string, $type )
{ 
        if ( $type != 'single' && $type == 'category' && ( strpos( $string, 'category' ) !== false ) )
        {
            $url_without_category = str_replace( "/category/", "/", $string );
            return trailingslashit( $url_without_category );
        }
    return $string;
}
 
add_filter( 'user_trailingslashit', 'remove_category', 100, 2);

This function intercepts the URL and using the variables passed to us by WordPress, we replace the word “category” with an empty string. In addition, we’ve given it a pretty high priority so that it’s one of the last things the URL will be subject to. You’ll find that if you simply leave the priority as the default of 10, it probably won’t work on your installation.

Using a Plugin

If you don’t want to mess around with potentially finicky settings or have the hassle of inserting and maintaining custom code, there are several plug-ins that will do the job for you. Ideally, I like to find add-ons that perform a number of functions at the same time for efficiency. In this case, the well-known Yoast SEO plug-in has a functionality to remove the category base.

In the plug-in settings, navigate to the “Advanced” section and in the “Permalinks” tab, simply place a checkmark next to the very first option to strip the category base:

checkbox

Any one of these three techniques might work for you depending on your expertise, and preferences. Using them, you can get more control over your WordPress URLs as well as the presentation of categories.

5 Comments on “How to Remove the Word “Category” From WordPress URLs”!

  1. Thanks for running a great site. Very informative.

    I used the recommendation you mentioned on how to remove category , it works great!

    But ever since my URL name is changed for category now when i go to http://cloudvedas.com/openstack/feed i am getting “Page not found” error . While the feed is still at http://cloudvedas.com/category/openstack/feed . How can i correct this? This is causing error for google crawler also and showing in my google search console URL error report. As crawler is trying the find the feed at http://cloudvedas.com/openstack/feed .

  2. Avatar

    Hi Bhagwad, Thanks bro, very helpful post. I was facing great difficulty finding out how to make my categories in http://ittech4all.com/blog/ work without using category word in link. i was earlier using first method but getting 404 errors. thanks to your post now with advance option in yoast plugin everything working right.

  3. Avatar

    I tried your custom php code but It’s not working. I found page not found. Could you fix & update your post. Thanks

Leave a Reply

This Website is Hosted by

Powered by RamNode

Disclosure: We receive a compensation from some of the companies whose products or services are presented on our website.