How to Remove the Word “Category” From WordPress URLs

Posted on

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.

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

Leave a Reply

Your email address will not be published. Required fields are marked *