How to Remove the Category Slug from WordPress URLs

Remove category slug

WordPress automatically adds category slug “/category/” to the URLs of category archive pages. For example, if you have a category called News, the default URL will be:

https://example.com/category/news/

Many website owners prefer a cleaner URL structure, like:

https://example.com/news/

Removing the category slug improves readability, enhances SEO, and makes URLs more user-friendly. In this article, we will explore different methods to achieve this.

Method 1: Using Code (Functions.php or WP Code Snippet Plugin) for Remove Category Slug

You can remove the category base manually by adding a small PHP snippet to your theme’s functions.php file or by using the WP Code Plugin. Follow these steps:

Step 1: Add the Code to Functions.php

  1. Go to your WordPress Dashboard → Appearance → Theme File Editor.
  2. Open the functions.php file of your child theme (if you don’t have a child theme, consider using the WP Code plugin instead).
  3. Add the following code snippet at the bottom of the file:
function custom_remove_category_base($category_link) {
    $category_link = str_replace('/category/', '/', $category_link);
    return $category_link;
}
add_filter('category_link', 'custom_remove_category_base');

4. Click Update File and save the changes.

Step 2: Flush Permalinks

After adding the code, you must refresh the permalink structure:

  1. Go to Settings → Permalinks in your WordPress dashboard.
  2. Click Save Changes (without making any modifications).
  3. Now, check your category URLs. The slug “/category/” should be removed.

 

Method 2: Using a Plugin (Easy & Recommended) for Remove Category Slug

If you’re not comfortable editing theme files, you can use a plugin. Some recommended plugins for removing the category slug are:

Remove Category URL
Yoast SEO (Premium Feature)
Permalink Manager Lite

Using “Remove Category URL” Plugin

  1. Install and activate the Remove Category URL plugin.
  2. Go to Settings → Permalinks and check if the category slug is removed.
  3. Flush the permalinks by clicking Save Changes.

This method is the easiest and requires no coding knowledge.


Method 3: Using .htaccess (Advanced Users Only) for Remove Category Slug

If the above methods don’t work, you can manually rewrite the URLs using .htaccess.

  1. Open your .htaccess file (located in your WordPress root directory).
  2. Add this code at the end:
    RewriteRule ^category/(.+)$ https://example.com/$1 [R=301,L]
  3. Save the file and refresh your website.

Warning: Editing .htaccess incorrectly can break your site. Always back up before making changes.

 

Troubleshooting Common Issues

  1. 404 Errors After Removing the Slug?
    • Go to Settings → Permalinks and click Save Changes to flush the permalinks.
  2. Changes Not Visible?
    • Clear your browser cache or try opening your site in an incognito window.
    • If using a caching plugin (WP Rocket, W3 Total Cache), clear the cache.
  3. Conflicts with Other Plugins?
    • Some SEO and permalink plugins may override custom settings. Try disabling them to test if they interfere.

Share it

Leave a Reply

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