unregister_taxonomy_for_object_type

Home » Functions » unregister_taxonomy_for_object_type

The unregister_taxonomy_for_object_type function in WordPress is used to remove a taxonomy from a specific post type. Taxonomies in WordPress are used to organize and classify content, such as categories or tags. By default, taxonomies can be associated with different post types, but sometimes we may need to unregister a taxonomy from a specific post type for various reasons.

The unregister_taxonomy_for_object_type function takes two parameters: the taxonomy name and the post type name. It unregisters the taxonomy from the specified post type, which means that the taxonomy will no longer be available for that post type. This can be useful when you want to restrict the use of a particular taxonomy for a specific post type or when you want to remove unnecessary or unused taxonomies from certain post types to simplify the content management process.

Here’s an example usage of the unregister_taxonomy_for_object_type function:

function unregister_taxonomy_from_post_type() {
    unregister_taxonomy_for_object_type('my_taxonomy', 'post');
}
add_action('init', 'unregister_taxonomy_from_post_type');

In this example, we have a custom taxonomy called ‘my_taxonomy’ that is registered for the ‘post’ post type. However, let’s say we no longer want to use this taxonomy for the ‘post’ post type. We can use the unregister_taxonomy_for_object_type function inside a custom function and hook it to the ‘init’ action. This will remove the ‘my_taxonomy’ taxonomy from the ‘post’ post type.

Remember to replace ‘my_taxonomy’ with the actual taxonomy name and ‘post’ with the desired post type.

By utilizing the unregister_taxonomy_for_object_type function, you can easily modify the taxonomies associated with specific post types in WordPress, providing you with more control over how content is organized and classified.

Learn More on WordPress.org

WordPress snippets using the unregister_taxonomy_for_object_type function

Register an account to save your snippets or go Pro to get more features.