2

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

1 Answer 1

2

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__),
    )
);
1
  • 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. Apr 18, 2013 at 11:16

Your Answer

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

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