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.

Remove category slug from permalinks in WordPressSimply 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.

You may also like...

8 Responses

  1. Anonymous says:

    welcome 😉

  2. wood plastic composite says:

    Very useful,thanks

  3. RB says:

    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?

  4. Anonymous says:

    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.

  5. Anonymous says:

    Have you considered the WP No Category Base plugin, I use it and it seems to work well.

  6. JR says:

    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?

  7. Shoaib Khan says:

    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

  8. Harash says:

    hey guys… please try new one:

    https://wordpress.org/plugins/remove-category-base-littlebizzy/

    Remove category base, no database needed, faster.

Leave a Reply

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