27

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.

Evan
  • 271
  • 1
  • 3
  • 4

7 Answers7

45

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' );
Evan
  • 1,316
  • 2
  • 14
  • 19
  • Worked for me! Seems like the most localized impact, as well. – Samuel Hulick Feb 11 '12 at 22:32
  • This works, but the link in the sidebar is still there! – Lars Ebert Mar 27 '14 at 15:22
  • Here is how to remove the sidebar menu entry: `function remove_menus(){ remove_menu_page('edit-tags.php?taxonomy=post_tag'); // Post tags } add_action( 'admin_menu', 'remove_menus' );` – pixeline Nov 23 '14 at 16:28
  • 2
    This was the simplest solution, also, the menu item was removed for me without the second script. – Ken Prince Dec 22 '14 at 19:51
  • 1
    One small bug I've found here: the taxonomy will still be included in the show options page when you edit your menus. To fix this, just pass in an additional args array: `register_taxonomy( 'post_tag', array(), array('show_in_nav_menus' => false) );` – Will Haynes Apr 04 '15 at 16:28
  • This helped me! I was using `unregister_taxonomy('product_tag')` (for woocommerce) and getting some weird errors in log. Re-registering it as en empty array basically had the same effect and I didn't get any errors – Brad Adams Mar 30 '17 at 18:54
  • @WillHaynes comment obligates the "Remove menus" action entirely. Its now gone everywhere. – Thomas Fellinger Oct 19 '20 at 02:37
21

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' );
}
cameronjonesweb
  • 2,435
  • 3
  • 25
  • 37
  • 1
    Might not be necessary but you could check if the taxonomy is already associated with the object type before removing it with `if ( is_object_in_taxonomy( 'post', 'post_tag' ) ) { ... }` – martisj Jan 01 '17 at 21:20
5

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');
    });
Den Media
  • 51
  • 1
  • 3
4

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]);
}
cnotethegr8
  • 7,342
  • 8
  • 68
  • 104
2

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/

  • 1
    This can't be used for built-in taxonomies so presumably this can't be used for 'tags'? – Rick Curran Oct 03 '16 at 11:02
  • For removing built-in taxonomy like tag we can use this function below: function mh_unregister_tags_for_posts() { unregister_taxonomy_for_object_type( 'post_tag', 'post' ); } add_action( 'init', 'mh_unregister_tags_for_posts' ); – Mahfuzul Hasan Sep 28 '17 at 10:39
1

Use it in 'admin_init' hook insetead not 'init'

function unregister_taxonomy(){
    register_taxonomy('post_tag', array());
}
add_action('admin_init', 'unregister_taxonomy');
user2957058
  • 270
  • 5
  • 16
1

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

Vlad
  • 365
  • 3
  • 6