How to overwrite a specific parameter in a core taxonomy?

Version 4.4 saw the introduction of the register_taxonomy_args filter in register_taxonomy() which you can use to filter the arguments used to register a taxonomy

/**
 * Filter the arguments for registering a taxonomy.
 *
 * @since 4.4.0
 *
 * @param array  $args        Array of arguments for registering a taxonomy.
 * @param array  $object_type Array of names of object types for the taxonomy.
 * @param string $taxonomy    Taxonomy key.
 */
$args = apply_filters( 'register_taxonomy_args', $args, $taxonomy, (array) $object_type );

So you can do the following:

add_filter( 'register_taxonomy_args', function ( $args, $taxonomy, $object_type )
{
    // Only target the built-in taxonomy 'category'
    if ( 'category' !== $taxonomy )
        return $args;

    // Set our capability 'edit_terms' to our value
    $args["capabilities"]["edit_terms"] = 'do_not_allow';

    return $args;
}, 10, 3);

On all older versions, you would either need to re-register the complete ‘category’ taxonomy or use the way you have done it in your question

EDIT

The Codex page for register_taxonomy says that

  • This function adds or overwrites a taxonomy.

That is exactly what it does, it either creates a custom taxonomy or completely overrides and register a core taxonomy, it does not add any extra arguments to the existing taxonomy

Leave a Comment