How do I remove a taxonomy from WordPress?

I’m creating different custom post types and taxonomies and I want to remove the ‘Post Tags’ taxonomy from the default ‘Posts’ post type. How do I go about doing this?

Thanks.

Related posts

Leave a Reply

7 comments

  1. I suggest you don’t mess with the actual global. Its safer to simply deregister the taxonomy from the post type: register_taxonomy is used for both creation and modification.

    function ev_unregister_taxonomy(){
        register_taxonomy('post_tag', array());
    }
    add_action('init', 'ev_unregister_taxonomy');
    

    To remove the sidebar menu entry:

    // Remove menu
    function remove_menus(){
        remove_menu_page('edit-tags.php?taxonomy=post_tag'); // Post tags
    }
    
    add_action( 'admin_menu', 'remove_menus' );
    
  2. Where it says ‘taxonomy_to_remove‘ is where you’ll enter the taxonomy you want to remove. For instance you can replace it with the existing, post_tag or category.

    add_action( 'init', 'unregister_taxonomy');
    function unregister_taxonomy(){
        global $wp_taxonomies;
        $taxonomy = 'taxonomy_to_remove';
        if ( taxonomy_exists( $taxonomy))
            unset( $wp_taxonomies[$taxonomy]);
    }
    
  3. Total unregister and remove (minimal PHP version 5.4!)

    add_action('init', function(){
            global $wp_taxonomies;
            unregister_taxonomy_for_object_type( 'category', 'post' );
            unregister_taxonomy_for_object_type( 'post_tag', 'post' );
            if ( taxonomy_exists( 'category'))
                unset( $wp_taxonomies['category']);
            if ( taxonomy_exists( 'post_tag'))
                unset( $wp_taxonomies['post_tag']);
            unregister_taxonomy('category');
            unregister_taxonomy('post_tag');
        });
    
  4. Use it in ‘admin_init’ hook insetead not ‘init’

    function unregister_taxonomy(){
        register_taxonomy('post_tag', array());
    }
    add_action('admin_init', 'unregister_taxonomy');