Remove Category Base in WordPress

Here’s how to remove your category base in WordPress:

Remove Category Base

function remove_cat_base( $string, $type )
global $wp_rewrite;
if ( $wp_rewrite->use_trailing_slashes == false )
if ( $type != ‘single’ && $type != ‘category’ )
return trailingslashit( $string );

if ( $type == ‘single’ && ( strpos( $string, ‘.html/’ ) !== false ) )
return trailingslashit( $string );

if ( $type == ‘category’ && ( strpos( $string, ‘category’ ) !== false ) )
$aa_g = str_replace( "/category/", "/", $string );
return trailingslashit( $aa_g );
if ( $type == ‘category’ )
return trailingslashit( $string );
return $string;

add_filter( ‘user_trailingslashit’, ‘remove_cat_base’, 55, 2 );

About Jean Galea

Jean Galea is a WordPress developer, entrepreneur and padel player. He is the founder of WP Mayor, the plugins WP RSS Aggregator and EDD Bookings, as well as the podcast. His personal blog can be found at

Related Articles

  • How to Remove Image Sizes in WordPress

    In an earlier post about image sizes in WordPress, we had shown you a way to choose which image sizes are available for choosing when you're inserting an image in…

  • How To Hide or Remove Categories from a WordPress Homepage

    When displaying your latest posts on the homepage, you might want to exclude some categories from displaying on this page. There are many reasons why you would want to do…

  • WordPress Means Freedom

    As a WordPress user, you get four core freedoms due to the open source nature of WordPress’ software license. These WordPress freedoms are in contrast to closed-source desktop software like…

10 Responses

  1. Mir
    Mir June 22, 2011 at 03:22 | | Reply

    Where do we add this code? Also, any chance of making this a plugin?

  2. Edgars
    Edgars July 7, 2011 at 04:33 | | Reply

    Great tutorial, however to make sure everything works, htaccess and category.php files must be modified as well

    htaccess, need to add:
    RedirectMatch 301 ^/category/(.+)$$1
    # OR
    RewriteRule ^category/(.+)$$1 [R=301,L]

    default title must be replaced with:
    <a href="“>

  3. Matthew
    Matthew July 28, 2011 at 13:53 | | Reply

    Nice job, it works fine. Thanks

  4. schools training
    schools training February 15, 2012 at 22:36 | | Reply

    It code is not working with sub categories , I just tried it on my blog. Please suggest

  5. Ivica
    Ivica June 26, 2012 at 18:27 | | Reply

    With new Yoast WordPress SEO you can now do it just with choosing an option in settings 🙂

  6. Joseph
    Joseph April 12, 2013 at 22:41 | | Reply

    Good post and comments
    If I use WordPress SEO, what happens to backlinks that contain the category base already? Will people be still redirected to the same post with new URL structure? 10x for your reply

  7. Chang
    Chang October 10, 2018 at 12:19 | | Reply

    Okay and why don’t make it be plugin like other??

    code is same?? not bloated?

Leave a Reply