I have several custom post types, which share two custom taxonomies (location and service). The custom taxonomies show up in each post type menu, and it just seems a little redundant. My client isn't going to need to edit those taxonomies, so I think it will just confuse them to see it repeated in every menu.

example post type

Is there a way to remove it from the admin menu for all but one of the post types, while still keeping it registered for all the post types? I know there are plugins to hide admin menu items, but I was wondering if I could just add something when I registered the custom taxonomy to prevent it?

Here's a sample of my taxonomy code:

// create custom taxonomy
function my_taxonomies() {

// location
    $labels = array(
        'name'              => _x( 'Location Category', 'taxonomy general name' ),
        'singular_name'     => _x( 'Location Category', 'taxonomy singular name' ),
        'search_items'      => __( 'Search Location Categories' ),
        'all_items'         => __( 'All Location Categories' ),
        'parent_item'       => __( 'Parent Location Category' ),
        'parent_item_colon' => __( 'Parent Location Category:' ),
        'edit_item'         => __( 'Edit Location Category' ), 
        'update_item'       => __( 'Update Location Category' ),
        'add_new_item'      => __( 'Add New Location Category' ),
        'new_item_name'     => __( 'New Location Category' ),
        'menu_name'         => __( 'Location Categories' ),
    );
    $args = array(
        'labels' => $labels,
        'hierarchical' => true,
        'show_ui'           => true,
        'show_admin_column' => true,
    );
    register_taxonomy( 'location', array( 'services','community','facilities','testimonials'), $args );
up vote 3 down vote accepted

You can use the remove_submenu_page function after registering the taxonomy.

This is how it works by default, it has 2 required parameters, the $menu_slug (these are the parent menus e.g. posts, media, pages, comments and so on), and the $submenu_slug (these are the children of those menus) which is what you're removing because your custom taxonomy will appear under posts or your custom post type:

<?php remove_submenu_page( $menu_slug, $submenu_slug ); ?>

If you're not sure what your $menu_slug is, check the remove_menu_page examples to see what you'd put in the first parameter. In your case, since it's under posts or your custom post type, it'll be edit.php.

For the second parameter, $submenu_slug, what I did was after registering the taxonomy I inspected the menu item with my browser inspector to see that the link of the menu item was to edit-tags.php?taxonomy=location.

So with your custom taxonomy 'location', you would write something like this:

add_action( 'admin_menu', 'remove_custom_tax_wp_menu', 999 );

function remove_custom_tax_wp_menu() {
  $page = remove_submenu_page( 'edit.php', 'edit-tags.php?taxonomy=location' );
  /* See reference: http://codex.wordpress.org/remove_submenu_page#Examples */
}

It should only affect the dashboard sidebar and not the metabox within your custom post types. Hope it helps!

  • 1
    Perfect! That's just what I needed. Thank you. – LBF Nov 14 '14 at 22:23
  • Actually, I had to modify it a bit to get it to work: remove_submenu_page('edit.php?post_type=community', 'edit-tags.php?taxonomy=location&amp;post_type=community'); – LBF Nov 15 '14 at 18:32

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.