unregister_taxonomy()
Cancels the registration of the specified taxonomy (removes the taxonomy).
In addition to removing the taxonomy from the general array of taxonomies, the following are also removed: rewrite rules for pretty permalinks, query parameters, and filters associated with the taxonomy.
Does not work with built-in taxonomies of tags and categories: post_tag and category. Does not work with those taxonomies that have the property _builtin = true.
1 time — 0.000039 sec (very fast) | 50000 times — 0.89 sec (very fast) | PHP 7.0.5, WP 4.5
Hooks from the function
Returns
true|WP_Error. True when removed. WP_Error on error or when the taxonomy does not exist.
Usage
unregister_taxonomy( $taxonomy );
- $taxonomy(string) (required)
- The name of the taxonomy to be removed (unregistered).
Examples
#1 Delete taxonomy
Suppose during the event init we registered the taxonomy genre. And then later we need to cancel it.
// taxonomy registration
add_action( 'init', 'create_genre_taxonomy' );
function create_genre_taxonomy(){
// Add tree taxonomy 'genre' (as categories)
register_taxonomy( 'genre', array('book'), array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'genre' ),
) );
}
// deleting the taxonomy
add_action( 'init', 'unregister_genre_taxonomy', 99 );
function unregister_genre_taxonomy(){
// cancel the tax only on individual pages
if( ! is_singular() ){
return;
}
unregister_taxonomy( 'genre' );
}
Notes
- Global. WP_Taxonomy[]. $wp_taxonomies List of taxonomies.
Changelog
| Since 4.5.0 | Introduced. |