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!