0

I have a problem with the address of the categories in my website.

At first, I have to say I checked all the similar topic and question in stackexchange, but none of them solved my problem. Problem is with Wp 3.8 .

We have some parent and some child categories, Also my permalink is:

/%postname%/

But the link of the parent and child categories are like this:

siteurl.com/parent/child/

I just want to remove the parent and have this:

siteurl.com/child/

I need a piece of code to solve this.

1 Answer 1

5

Add this code to your functions.php,

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,
    ) );

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.