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've registered a new content type with following -

register_post_type('news', array(
    'labels' => array(
        'name' => __( 'News'),
        'singular_name' => __( 'News'),     
        'add_new' => _x( 'Add New News', 'News'),
        'add_new_item' => __( 'Add New News'),
        'edit_item' => __( 'Edit News'),
        'new_item' => __( 'New News'),
        'view_item' => __( 'View News Details'),
        'search_items' => __('Search News')         
      ),
    'public' => true,
    'show_ui' => true,
    'menu_position' => 6,
    'has_archive' => false,
    'rewrite' => array('slug'=>'news'),
    'supports' => array('title', 'editor' ),
    'taxonomies' => array('category'),
    'menu_icon' => plugins_url('icons/news.png', __FILE__),
    )
);

This does generate admin menu item as follows --

enter image description here

or

enter image description here

Is it possbile to remove repeated link for menu item News that comes on hover of main menu item. Because, the main menu item News ( in bold letter ) takes admin to same page as sub-menu item news does. In short- i want to have only two options as sub menus .. those are Add New News and Categories. Is this possbile ??

I tried using following--

add_action('admin_menu', 'remove_news_subitem');
function remove_news_subitem() {
    global $submenu;
    unset($submenu['edit.php?post_type=news']);
}

But this removes all submenus.

I believe no such hook is present to do this. And only option I could imagine is to edit core files. But that I strongly don't want to do.

Possible way to do this using jQuery when menu items render on domReady. But this is ugly. Can it be done from php itself??

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Just added 'all_items' => __( '' ), in labels array.

Replace your code with below code

register_post_type('news', array(
    'labels' => array(
        'name' => __( 'News'),
        'singular_name' => __( 'News'),     
        'add_new' => _x( 'Add New News', 'News'),
        'add_new_item' => __( 'Add New News'),
        'edit_item' => __( 'Edit News'),
        'new_item' => __( 'New News'),
        'view_item' => __( 'View News Details'),
        'all_items'          => __( '' ),
        'search_items' => __('Search News')         
      ),
    'public' => true,
    'show_ui' => true,
    'menu_position' => 6,
    'has_archive' => false,
    'rewrite' => array('slug'=>'news'),
    'supports' => array('title', 'editor' ),
    'taxonomies' => array('category'),
    'menu_icon' => plugins_url('icons/news.png', __FILE__),
    )
);
share|improve this answer
    
I found remove_submenu_page() does same thing. But your approach is what I'm going to adapt. I'm having number of such post types and calling remove_submenu_page() for each is not good. This solution clean and simple avoiding multiple func calls. –  SachinGutte Apr 18 '13 at 11:16

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.