1

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 );

1 Answer 1

3

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
  • 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
    Commented Nov 15, 2014 at 18:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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