0

I want this url: =>
mydomain.com/genre/chant

to be rewritten as =>
mydomain.com/chambers/chant.

I want the users to access mydomain.com/chambers/chant instead of mydomain.com/genre/chant.

genre is a custom taxonomy for custom post type tracks. This custom taxonomy is registered in the theme. I want to change its slug from genre to chambers in my plugin. How do I do it?

I tried the below rewrite url code, but it did not work:

add_rewrite_rule('^chambers/?','index.php?post_type=tracks&taxonomy=genre','top');

1 Answer 1

0

Try using the below code to overwrite arguments of already registered taxonomies.

function wp_modify_taxonomy() {

    // get the arguments of the already-registered taxonomy
    $custom_category_args = get_taxonomy( 'genre' );

    // make changes to the args
    $custom_category_args->rewrite['slug'] = 'chambers';
    $custom_category_args->rewrite['with_front'] = false;

    // re-register the taxonomy
    register_taxonomy( 'genre', 'chambers', (array) $custom_category_args );
}
add_action( 'init', 'wp_modify_taxonomy', 11 );

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.