Wordpress - Remove duplicate main - submenu in admin?

Hi @JM at Work:

Yes, it is unfortunately that the submenu page is added for every menu page. It would be nice if there were an option but alas, there currently is not.

To remove the submenu page option in WordPress 3.1 or great use remove_submenu_page() with code like this in your theme's functions.php file, or in a .php file of a plugin you might be writing:

add_action( 'admin_menu', 'yoursite_admin_menu' );
function yoursite_admin_menu() {
  add_menu_page( 'Forms', 'Forms', 'administrator', 'forms', 'forms_job_menupage_cb' );
  add_submenu_page( 'forms', 'Job Applications', 'Job Applications', 'administrator', 'job-applications', 'forms_job_menupage_cb' );
  add_submenu_page( 'forms', 'Quote Requests', 'Quote Requests', 'administrator', 'quote-req', 'forms_req_menupage_cb' );
  add_submenu_page( 'forms', 'Contact', 'Contact', 'administrator', 'contact', 'forms_contact_menupage_cb' );
  remove_submenu_page('forms','forms');
}

If you are still using WordPress 3.0 you have to unset() an element of the global variable $submenu like this:

add_action( 'admin_menu', 'yoursite_admin_menu' );
function yoursite_admin_menu() {
  add_menu_page( 'Forms', 'Forms', 'administrator', 'forms', 'forms_job_menupage_cb' );
  add_submenu_page( 'forms', 'Job Applications', 'Job Applications', 'administrator', 'job-applications', 'forms_job_menupage_cb' );
  add_submenu_page( 'forms', 'Quote Requests', 'Quote Requests', 'administrator', 'quote-req', 'forms_req_menupage_cb' );
  add_submenu_page( 'forms', 'Contact', 'Contact', 'administrator', 'contact', 'forms_contact_menupage_cb' );
  unset($GLOBALS['submenu']['forms'][0]);
}

Assign the first submenu slug similar to the parent menu. In your case, replace 'job-applications' with the slug of the main menu 'forms'.

add_menu_page( 'Forms', 'Forms', 'administrator', 'forms', 'forms_job_menupage_cb' );
add_submenu_page( 'forms', 'Job Applications', 'Job Applications', 'administrator', 'forms', 'forms_job_menupage_cb' );
add_submenu_page( 'forms', 'Quote Requests', 'Quote Requests', 'administrator', 'quote-req', 'forms_req_menupage_cb' );
add_submenu_page( 'forms', 'Contact', 'Contact', 'administrator', 'contact', 'forms_contact_menupage_cb' );

Tags:

Admin Menu