How to remove parent category slug in Permalinks for WordPress
WordPress has excellent options to categorize your posts. You can add them to any number of categories and subcategories, specify tags for them or even classify them under custom taxonomies. If you have a fairly large site, you might be interested in using subcategories for categorizing your posts in a better way. WordPress by default lets you have the category name in the permalinks but if you use subcategory, both the category and subcategory slug appear on your permalinks. If you need to remove the parent category slug from Permalinks in WordPress, you can do it using a plugin or modifying your theme’s functions.php file.
Simply using the subcategory slug without the category slug will make the URL shorter and more relevant. You can remove the parent category slug from Permalinks in WordPress using No category parents WordPress plugin. Download and install the plugin and it will automatically remove the parent category from your permalinks. You don’t need to configure anything.
You can also attain the same results by manually editing your theme’s functions.php file. Open functions.php file from your current theme’s folder. Now add the following line of code at the end of the file.
[php]
<code>add_action( ‘init’, ‘build_taxonomies’, 0 );
function build_taxonomies() {
register_taxonomy( ‘category’, ‘post’, array(
‘hierarchical’ => true,
‘update_count_callback’ => ‘_update_post_term_count’,
‘query_var’ => ‘category_name’,
‘rewrite’ => did_action( ‘init’ ) ? array(
‘hierarchical’ => false,
‘slug’ => get_option(‘category_base’) ? get_option(‘category_base’) : ‘category’,
‘with_front’ => false) : false,
‘public’ => true,
‘show_ui’ => true,
‘_builtin’ => true,
) );
}</code>
[/php]
This will do the trick and you’ll be able to remove the category slug from WordPress permalinks.
welcome 😉
Very useful,thanks
Both of the option presented above do remove the parent category from URLs, but they break all of your links to category archives. Do you know a way of preventing this from happening?
You should first set an option to remove the category base from the URL for
the category page. use scategory permalinks plugin or some other
decategorizing plugins to remove the category base from urls. It will then
work fine.
Have you considered the WP No Category Base plugin, I use it and it seems to work well.
Thanks for this. Very nifty. But what if I want to remove the subcategory slug from the URL and just retain the parent slug? Ideally, it should be domain/parent-slug/post-title. How do I do this?
This seems working but creating issue with my tag and archive URL. Then with more research I found this which removed it without any additional code or plugin. Just a simple change in permalink setting from admin. Hope this help to some one => http://www.phpweb.info/wordpress/remove-category-tag-base-wordpress-url
hey guys… please try new one:
https://wordpress.org/plugins/remove-category-base-littlebizzy/
Remove category base, no database needed, faster.