How to modify a taxonomy that’s already registered

register_taxonomy() is the tool for the job. From the Codex:

This function adds or overwrites a taxonomy.

One option would be to copy the register_taxonomy() $args and modify them. However, that would mean that any future changes to the original register_taxonomy() code would be overwritten.

Therefore, at least in this case, it’s preferable to get the original arguments, modify the ones I want to change, and then re-register the taxonomy. Inspiration for this solution goes to @Otto in this answer to a similar question about custom post types.

Using the people custom post type and people_category taxonomy from the example, this’ll do it:

function wpse_modify_taxonomy() {
    // get the arguments of the already-registered taxonomy
    $people_category_args = get_taxonomy( 'people_category' ); // returns an object

    // make changes to the args
    // in this example there are three changes
    // again, note that it's an object
    $people_category_args->show_admin_column = true;
    $people_category_args->rewrite['slug'] = 'people';
    $people_category_args->rewrite['with_front'] = false;

    // re-register the taxonomy
    register_taxonomy( 'people_category', 'people', (array) $people_category_args );
}
// hook it up to 11 so that it overrides the original register_taxonomy function
add_action( 'init', 'wpse_modify_taxonomy', 11 );

Note above that I typecast the third register_taxonomy() argument to the expected array type. This isn’t strictly necessary as register_taxonomy() uses wp_parse_args() which can handle an object or array. That said, register_taxonomy()‘s $args are supposed to be submitted as an array according to the Codex, so this feels right to me.

Leave a Comment