Here’s how to remove your category base in WordPress:
[php]
/*——————
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 );
[/php]
9 Responses
Okay and why don’t make it be plugin like other??
https://wordpress.org/plugins/remove-category-base-littlebizzy/
code is same?? not bloated?
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
Yes they will be redirected Joseph. You can try it out 🙂
With new Yoast WordPress SEO you can now do it just with choosing an option in settings 🙂
It code is not working with sub categories , I just tried it on my blog. Please suggest
Nice job, it works fine. Thanks
Thanks for your input!
Where do we add this code? Also, any chance of making this a plugin?
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.