unregister_taxonomy_for_object_type()
Remove an already registered taxonomy from an object type.
1 time — 0.000001 sec (speed of light) | 50000 times — 0.02 sec (speed of light) | PHP 7.0.32, WP 5.1
Hooks from the function
Return
true|false
. True if successful, false if not.
Usage
unregister_taxonomy_for_object_type( $taxonomy, $object_type );
- $taxonomy(string) (required)
- Name of taxonomy object.
- $object_type(string) (required)
- Name of the object type.
Examples
#1 Remove tags from use for blog posts
This example would decouple "Tags" from "Posts". I.e. the "Tags" item would disappear from the "Posts" menu, and the "Tags" metabox would disappear when editing posts. There will be no real removal of the "Tags" taxonomy.
add_action( 'init', 'wpkama_unregister_tags', 99 ); function wpkama_unregister_tags(){ unregister_taxonomy_for_object_type( 'post_tag', 'post' ); // The same can be done with "Categories" // unregister_taxonomy_for_object_type( 'category', 'post' ); }
This code will remove the "Tags" admin menu item, the "Tags" column when viewing the list of posts and the Tags metabox when editing a single post.
Notes
- Global. WP_Taxonomy[]. $wp_taxonomies The registered taxonomies.
Changelog
Since 3.7.0 | Introduced. |