How to Remove Category from WordPress URL ( 4 Ways )

In WordPress websites, the permalinks structure by default is made in such a way that, when you are viewing any page or a post that comes under some category, WordPress automatically adds a category prefix in the URL. For example, the Domain name/category/slug of the page title.

A category prefix included in a website URL makes it well organized and also makes the URL user-friendly; however, if you don’t like the category name appearing in the URL and want to remove it from your Website URL but didn’t know how to do it, well, don’t worry, in this guide, I will be showing you how to remove category from WordPress URL.

Before you know how to remove category from WordPress URL, let’s first learn why category is added to the URL and whether you should remove it from the URL or not.

Why does WordPress add category to the URL?

In WordPress, there is a file in your theme named “Archive.php” this file organizes a list of posts under a specific post type, category, tags, etc. So with the help of these archive pages which are generated through Archive.php, the category is added to the post or page URL.

Why Remove Category from WordPress URL?

The word category included in the URL of a website makes it simpler for the site visitors to know that the page they are viewing is a category of something, but the URL may become longer with this. So if a site owner wants to make their Website URL shorter and cleaner and wants to remove the category from WordPress URL, then in this guide, I will be sharing four quick methods through which you can achieve this.

Note: Whenever you modify your Website URLs, then add redirects also from your old URL to the new one, so if there is a backlink of this old URL on some other site and when they click on that link, they shouldn’t receive an error

4 Ways to Remove Category from WordPress URL

To remove category from WordPress URL, I have come up with four ways to help you get rid of category from the URL. Let’s discuss each method one by one in detail

In this first method, I will remove category from URL in WordPress Permalinks settings. To do so, log in to your WordPress Dashboard > Settings > Permalinks. In the permalinks tab, change your Permalink structure to Custom Structure and add %category% after the domain name like this:

Selecting permalink structure in WordPress settings

Now, scroll down below and there you will see Category base, Add a comma( . ) in that field and save the changes.

Adding comma in category base

In this way, the word category will be removed from your URL.

You May Like:

How to Remove index.php from URL WordPress [ Fixed ]

How to Change Link Color in WordPress ( 4 Methods )

How to get Current Page URL WordPress ( 2 Easy Ways)

2) Remove Category from WordPress URL With PHP code

Removing category from WordPress URL with PHP is yet another method; you don’t require any coding experience for this; just follow our steps, and the word category will be completely removed from your Website URL.

  1. login to your WordPress Dashboard.
  2. Go to Appearance > Theme Editor.
  3. In the theme editor, open the function.php file and add the below code there:
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);

Update your theme file, and check your site to verify that the category has been removed from your Website URL.

Make sure to backup your site before working with code since a single line of coding mistake can crash whole website. However if you don’t know how to take backup of your WordPress site for free, no worries, I have have written separate guide on how to take backup of WordPress site for free

Note: If in the future you change your theme then this code will be gone from function.php file, so better install Code Snippet plugin and add the above code there in this way changing your theme won’t affect this code.

And to properly edit function.php file or you can say add php code to WordPress checkout this guide on How to Edit functions.php in WordPress

3) Remove Category from URL by Modifying .htaccess file

The above two methods will work for you, but if you want to gain more knowledge and see more ways, modifying the .htaccess file to remove category from the WordPress URL is another method. This method is technical; it does not require coding knowledge as I will be showing step by step process, but it’s a risky method as any mistake in code files can damage your site.

Below are the steps to modify your .htaccess file to remove category from WordPress URL:

  1. Login to your hosting account and open your Cpanel Dashboard
  2. Go to file manager
  3. In the file manager, you will see public_html; click on it
  4. In public_html, look for the .htaccess file; if you couldn’t find it, then it may be hidden.
  5. Now, on your screen, there will be a settings menu; open it, and there enable view hidden files; in this way, the .htaccess file will become visible.
  6. At last, open your .htaccess file and insert the below code at the bottom of the file and update it:
RewriteRule ^category/(.+)$ http://www.site.com/$1 [R=301,L]

The above were coding methods, but if you don’t want to use code, I will also show you how to remove category from WordPress URL through plugins.

4) Remove Category from WordPress URL with plugins.

As you know, WordPress is mainly powered by its plugins, so let’s discuss some of the WordPress plugins that will help you remove category from your site URL

1 Yoast SEO Plugin

SEO Yoast plugin

Yoast SEO plugin is a powerful WordPress plugin that helps bloggers to rank their Websites on top in search engines. This plugin provides many useful features, and removing category from your WordPress Website URL is one of them.

To use this feature, install and activate this plugin, then visit your WordPress Dashboard > look for Yoast SEO icon > Search Appearance; now in the Search Appearance, scroll down to see Category URLs, there you have the option to keep or remove the category prefix. Once you select the remove option, save the changes and verify that the category is not showing anymore on your site URL.

2 Rank Math SEO Plugin

Rank Math SEO plugin for removing category from URL

Rank Math simplifies the process of removing the category from your WordPress URLs. To do so, install and activate this plugin and then navigate to Rank Math tab in WordPress Dashboard. There click on General settings > WooCommerce, now you will see different options, you will need to toggle Remove Category Base option which will then remove category from WordPress URLs.

3 Remove Category URL

remove category URL

Remove Category URL is another plugin that helps you remove category from WordPress URL; this plugin works straight out of the box and does not require any configuration. You just have to install and activate this plugin, and it will remove the category from your Website URL.

With these above-discussed methods, you can remove or hide category from WordPress URL, but if you just want to replace the category word with another word like tutorials, blogs, topics, or anything similar, then it can also be achieved.

Changing Category Prefix with another Word

In order to change the category word/prefix with some other word, go to your WordPress Dashboard > Settings > Permalinks. In the Permalinks tab, change the permalink structure to custom structure, and add category and post name after domain like this: /%category%/%postname%.

Now scroll down below, and you will see Category Base, there, write any word that is suitable to you, and that will change/replace the category prefix with the word you have given.

FAQ( How to remove category from WordPress URL )

How do I remove the category of my WordPress URL?

The simplest method to remove category from WordPress URL is to remove category in your permalinks settings; to do so, go to WordPress Dashboard > Settings > Permalinks.
In the permalinks tab, you can change your Permalink structure to Custom Structure and add %category% after your website domain name. After doing it, scroll down below, there you will see Category base, Add a comma( . ) in that field and save the changes.

How do I change the category of my WordPress URL?

To change category from WordPress URL, go to your WordPress Dashboard > Settings > Permalinks. Now in the Permalinks tab, change the permalink structure to custom structure, and add category and post name after domain like the following:

/%category%/%postname%.

After that scroll down below, and there you can see Category Base, so there, write any word that you want to replace with category, this will change/replace the category prefix with the word you have given.

Conclusion

Finally, you would be now well informed on how to remove category from WordPress website URL, I shared four methods with you, and all of them are well explained. It’s up to you which method you can use but if you want me to suggest the best and quick method then I will prefer the first method since you don’t need coding skills for it and it is also simple and easy to follow.

If you just want to change the category text to some other text then I also shared a method for this. I hope my guide would help you solve your problem but still if you want to ask some queries then comment down below I will be happy to assist you and respond as soon as possible

Also if you want me to cover some other topics/issues in WordPress then feel free to contact me through the Contact us page. Thank you for reading, have a nice day…!

Hamza Afridi is a Full stack Web & WordPress developer and writer with 5+ years of experience. He is Founder of webtalkhub.com, a blog on web development, SEO, and digital marketing tutorials. He enjoys learning and sharing new technologies.

Leave a Comment