unregister_taxonomy()
Unregisters a taxonomy.
Can not be used to unregister built-in taxonomies.
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
Return
true|WP_Error
. True on success, WP_Error on failure or if the taxonomy doesn't exist.
Usage
unregister_taxonomy( $taxonomy );
- $taxonomy(string) (required)
- Taxonomy name.
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. |