Skip to content

Instantly share code, notes, and snippets.

@liranop
Created October 6, 2022 17:00
Show Gist options
  • Save liranop/118be6fa5654d07dfa76298d312e29a4 to your computer and use it in GitHub Desktop.
Save liranop/118be6fa5654d07dfa76298d312e29a4 to your computer and use it in GitHub Desktop.
change taxonomy url to domain/base_url/parent-term/child-term
function modify_taxonomy() {
// get the arguments of the already-registered taxonomy
$taxonomy = 'taxonomy_name';
$cpt_type = array( 'post' , 'gallery');
$base_url = 'blog';
$category_args = get_taxonomy( $taxonomy ); // returns an object
$category_args->show_admin_column = true;
$category_args->query_var = true;
$category_args->rewrite = array( 'hierarchical' => true, 'with_front' => false, 'slug' => $base_url );
// re-register the taxonomy
register_taxonomy( $taxonomy, $cpt_type, (array) $category_args );
}
// hook it up to 11 so that it overrides the original register_taxonomy function
add_action( 'init', 'modify_taxonomy', 11 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment