Remove Category Name from Category’s URL using Code

Remove category text/name from category’s slug/url. Just paste given code on active theme’s functions.php. and category name automatically removed from category’s url.

Example with category name in URL
http://thekroyaard.com/category/how-to/wordpress

Example without category name in URL
http://thekroyaard.com/how-to/wordpress 

How to Do This

  • Open cpanel then open public_html.
  • Open wp-content then open themes folder.
  • Open active theme’s folder then open functions.php file.

Code

function therkoyaard_remove_categoryname_from_url( $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', 'therkoyaard_remove_categoryname_from_url', 100, 2);
  • Paste given code and SAVE functions.php file.

Hope this code worked on your theme, Thanks for visiting