Skip to content

Instantly share code, notes, and snippets.

@everaldomatias
Created June 23, 2021 18:00
Show Gist options
  • Save everaldomatias/130c56bcec640b9a9733f1d45178e197 to your computer and use it in GitHub Desktop.
Save everaldomatias/130c56bcec640b9a9733f1d45178e197 to your computer and use it in GitHub Desktop.
update-registered-taxonomy.php
<?php
/**
* Change `post_tag` to hierarchical example
*
* @author Everaldo Matias <https://everaldo.dev>
*
* @see https://developer.wordpress.org/reference/hooks/init/
* @see https://developer.wordpress.org/reference/functions/get_taxonomy/
* @see https://developer.wordpress.org/reference/functions/register_taxonomy/
*/
function update_registered_taxonomy() {
// get the arguments of the already-registered taxonomy
$args = get_taxonomy( 'post_tag' ); // returns an object
// make changes to the args
$args->hierarchical = true;
$args->rewrite['slug'] = 'people';
// re-register the taxonomy
register_taxonomy( 'post_tag', 'post', (array) $args );
}
add_action( 'init', 'update_registered_taxonomy', 99 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment