How do I remove a taxonomy from Wordpress?

前端 未结 7 651
一个人的身影
一个人的身影 2021-02-01 17:10

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?

相关标签:
7条回答
  • 2021-02-01 17:41

    There is new function to remove taxonomy from WordPress.

    Use unregister_taxonomy( string $taxonomy ) function

    See details: https://developer.wordpress.org/reference/functions/unregister_taxonomy/

    0 讨论(0)
  • 2021-02-01 17:45

    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');
        });
    
    0 讨论(0)
  • 2021-02-01 17:46

    add_action('admin_menu', 'remove_menu_items'); function remove_menu_items() { remove_submenu_page('edit.php','edit-tags.php?taxonomy=post_tag'); }

    0 讨论(0)
  • 2021-02-01 17:48

    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]);
    }
    
    0 讨论(0)
  • 2021-02-01 17:51

    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' );
    
    0 讨论(0)
  • 2021-02-01 17:53

    Perhaps a more technically correct method would be to use unregister_taxonomy_for_object_type

    add_action( 'init', 'unregister_tags' );
    
    function unregister_tags() {
        unregister_taxonomy_for_object_type( 'post_tag', 'post' );
    }
    
    0 讨论(0)
提交回复
热议问题