10 May 2011 ~ 5 Comments

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.

admin
Author: Admin
I am a technology blogger. I love to write about blogging, SEO, Wordpress, Internet, Web 2.0, Online Tools, Social Networking, Software, Gadgets and more.
Author Website:

Related Posts

  1. Update Simple Tags plugin to fix Permalink redirect in WordPress 3.1
  2. Fix custom permalinks structure in WordPress on a localhost setup
  3. Enable basic screen options after fresh installation of WordPress 3.1
  4. Help improve the new WordPress 3.2 Beta and the Twenty Eleven theme
  5. How to preview post as you type in WordPress

  • http://www.techwoodn.com/ wood plastic composite

    Very useful,thanks

  • Anonymous

    welcome ;)

  • RB

    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?

  • Anonymous

    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.

  • Anonymous

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