Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm creating a custom post type and have added categories taxanomy. This can be done in two ways:

// In $args array
'taxonomies' => array('category'),

// or calling a function
register_taxonomy_for_object_type( 'category', 'my_custom_post_type_name' );

In both cases, an additional child-menu item appears in my custom post menu in the left admin menu.

Categories are already showing under Post menu, so I don't need it to display again. Any way of preventing this?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

This was hacked together very quickly. I don't for sure if there will be problems with translation, but I be there would be.

function remove_menu_from_cpt() {
  global $submenu;
  $post_type = 'book';
  $tax_slug = 'post_tag';
  if (isset($submenu['edit.php?post_type='.$post_type])) {
    foreach ($submenu['edit.php?post_type='.$post_type] as $k => $sub) {
      if (false !== strpos($sub[2],$tax_slug)) {
        unset($submenu['edit.php?post_type='.$post_type][$k]);
      }
    }
  }
}
add_action('admin_menu','remove_menu_from_cpt');

It used the 'book' post type and post tags, because that was convenient for me to test, but it pretty obvious what needs to change to make this work for your case-- I believe you need:

$post_type = 'my_custom_post_type_name';
$tax_slug = 'category';
share|improve this answer
    
That worked like a charm. Thanks :-) –  Steven Jul 4 '13 at 19:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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