Remove Category Base in WordPress

Written by Jean Galea
Written by Jean Galea
Want to remove the useless /category/ from your WordPress categories permalinks? If yes, put this code in your functions.php and you're done!

Partner Sponsors


Full disclosure: If you purchase through a link on our site, we may earn a commission. Learn more.

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 );

This article was filed in our archives.
Written by Jean Galea
Jean Galea is an investor, entrepreneur, and blogger. He is the founder of WP Mayor, the plugins WP RSS Aggregator and Spotlight, as well as the podcast. His personal blog can be found at

In this article

Discover More

9 Responses

  1. 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

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

    1. You have to add it in the theme’s functions.php file. There are also some plugins that implement this in the WordPress repository, although I haven’t tested them recently.

Share Your Thoughts

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

New discoveries, every week.
Join thousands of designers, developers, and builders that come to WP Mayor to find the best guides, tools, and services for their next website. One email, once a week.
WP Mayor Newsletter

Claim Your Free Website Tip 👇

Leave your name, email and website URL below to receive one actionable improvement tip tailored just for your website within the next 24 hours.

"They identified areas for improvement that we had not previously considered." - Elliot

By providing your information, you'll also be subscribing to our weekly newsletter packed with exclusive content and insights. You can unsubscribe at any time with just one click.

What's missing?