WordPress.org

Forums

Remove metabox for custom taxonomy (9 posts)

  1. jadedstudio
    Member
    Posted 4 years ago #

    Hi, I've added a custom taxonomy ('artist') to my post using register_taxonomy function in functions.php.

    $labels = array(
        'name' => _x( 'Add an Artist', 'taxonomy general name' ),
        'singular_name' => _x( 'Artist', 'taxonomy singular name' ),
        'search_items' =>  __( 'Search Artists' ),
        'popular_items' => __( 'Popular Artists' ),
        'all_items' => __( 'All Artists' ),
        'parent_item' => null,
        'parent_item_colon' => null,
        'edit_item' => __( 'Edit Artist' ),
        'update_item' => __( 'Update Artist' ),
        'add_new_item' => __( 'Add New Artist' ),
        'new_item_name' => __( 'New Artist Name' ),
        'separate_items_with_commas' => __( 'Separate artists with commas' ),
        'add_or_remove_items' => __( 'Add or remove artists' ),
        'choose_from_most_used' => __( 'Choose from the most used artists' )
      ); 
    
      register_taxonomy('artist','post',array(
        'hierarchical' => false,
        'labels' => $labels,
    	'public' => true,
    	'show_tagcloud' => true,
        'show_ui' => true,
        'query_var' => 'artist',
        'rewrite' => array( 'slug' => 'artist' ),
      ));

    However, I need to hide the custom taxonomy metabox from some of my new post screens. I've tried to use remove_meta_box( 'artist' , 'post' , 'normal' ); wrapped in an if statement, however, with or without the if statement the metabox remains.

    function remove_artist_meta() {
    	remove_meta_box( 'artist' , 'post' , 'normal' );
    }
    add_action( 'admin_menu' , 'remove_artist_meta' );

    Does anyone know of the first parameter for remove_meta_box is correct as artist, or would it be something else??

  2. serdominik
    Member
    Posted 4 years ago #

    you must change in register_taxonomy:
    'show_ui' => false,

  3. opicron
    Member
    Posted 4 years ago #

    @serdomonik,

    That is correct. But I can imagine that someone wants to remove the Metabox from the Post Edit itself, but not from the Admin panel as an seperate menu.

    Actually I am looking for this myself. I need the Taxonomy as an seperate menu item in my Admin menu, but not as an UI Metabox in the Post editor.

    Any way to fix this functionality?

  4. handsofaten
    Member
    Posted 4 years ago #

    You're almost there. First of all, the context for boxes added to the side of the edit page (where the taxonomies typically show up) is 'side' (not 'normal'). Second, the taxonomy edit boxes are registered as tagsdiv-{taxonomy name}. So, this works for me (using your artist taxonomy as an example):

    function remove_artist_meta() {
    	remove_meta_box( 'tagsdiv-artist', 'post', 'side' );
    }
    
    add_action( 'admin_menu' , 'remove_artist_meta' );
  5. opicron
    Member
    Posted 4 years ago #

    nice-- actually i found this out by firebuggin' the admin screen. but i lost track of this thread, thank you for taking the time to post the answer.

  6. Manny Fleurmond
    Member
    Posted 4 years ago #

    Found something about the solution: it removes taxonomy metaboxes that behave like tags but not categories.

  7. Ken Dirschl
    Member
    Posted 3 years ago #

    I noticed the same as @Funkatronic. Non-hierarchical taxonomies can be removed using 'tagsdiv-custom_taxonomy_slug', but hierarchical taxonomies will not be removed.

    Tried 'categorydiv-custom_taxonomy_slug' as well but no success.

    anyone have a solution?

  8. Manny Fleurmond
    Member
    Posted 3 years ago #

    Found a solution a while ago that I forgot to post here. Hierarchical taxonomy boxes can be removed by using custom_taxonomy_slugdiv

  9. Ken Dirschl
    Member
    Posted 3 years ago #

    that's great @Funkatronic. very useful.

Topic Closed

This topic has been closed to new replies.

About this Topic