wordpress custom post type remove duplicate menu item

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 —

Read More

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??

Related posts

Leave a Reply

1 comment

  1. 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__),
        )
    );