unregister_taxonomy

Unregisters a taxonomy.

Description

(bool|WP_Error) unregister_taxonomy( (string) $taxonomy ); 

Can not be used to unregister built-in taxonomies.

Returns (bool|WP_Error)

True on success, WP_Error on failure or if the taxonomy doesn't exist.

Parameters (1)

0. $taxonomy (string)
Taxonomy name.

Usage

  1. if ( !function_exists( 'unregister_taxonomy' ) ) { 
  2. require_once ABSPATH . WPINC . '/taxonomy.php'; 
  3.  
  4. // Taxonomy name. 
  5. $taxonomy = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = unregister_taxonomy($taxonomy); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/taxonomy.php  
  1. function unregister_taxonomy( $taxonomy ) { 
  2. if ( ! taxonomy_exists( $taxonomy ) ) { 
  3. return new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy.' ) ); 
  4.  
  5. $taxonomy_object = get_taxonomy( $taxonomy ); 
  6.  
  7. // Do not allow unregistering internal taxonomies. 
  8. if ( $taxonomy_object->_builtin ) { 
  9. return new WP_Error( 'invalid_taxonomy', __( 'Unregistering a built-in taxonomy is not allowed' ) ); 
  10.  
  11. global $wp_taxonomies; 
  12.  
  13. $taxonomy_object->remove_rewrite_rules(); 
  14. $taxonomy_object->remove_hooks(); 
  15.  
  16. // Remove the taxonomy. 
  17. unset( $wp_taxonomies[ $taxonomy ] ); 
  18.  
  19. /** 
  20. * Fires after a taxonomy is unregistered. 
  21. * @since 4.5.0 
  22. * @param string $taxonomy Taxonomy name. 
  23. */ 
  24.  
  25. return true;