register_taxonomy()
es la herramienta para el trabajo. Del Codex:
Esta función agrega o sobrescribe una taxonomía.
Una opción sería copiar el register_taxonomy()
$args
y modificarlos. Sin embargo, eso significaría que cualquier cambio futuro en el código register_taxonomy()
original se sobrescribiría.
Por lo tanto, al menos en este caso, es preferible obtener los argumentos originales, modificar los que quiero cambiar y luego volver a registrar la taxonomía. La inspiración para esta solución va a @Otto en esta respuesta a una pregunta similar sobre tipos de correos personalizados .
Usando el tipo de publicación personalizada people
y la taxonomía people_category
del ejemplo, esto lo hará:
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 );
Tenga en cuenta que escribí el tercer argumento register_taxonomy()
al tipo de matriz esperado. Esto no es estrictamente necesario ya que register_taxonomy()
usa wp_parse_args()
que puede manejar un object
o array
. Dicho esto, register_taxonomy()
's $args
deben enviarse como array
de acuerdo con el Codex, por lo que me parece correcto.