How to remove parent category slug in Permalinks for WordPress

1 Star2 Stars3 Stars4 Stars5 Stars (5 votes, average: 2.40 out of 5)
Loading...
May 10, 2011

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

Post a comment