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.

When I use add_menu_page & add_submenu_page to add menu items,

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' );

I will get something like

  • Forms
    • Forms
    • Job Applications
    • Quote Requests
    • Contacts

Is it possible to create it such that it becomes

  • Forms
    • Job Applications
    • Quote Requests
    • Contacts

In other words Forms will link to Job Applications and I dont want the extra Forms submenu item

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

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]);
}
share|improve this answer
add comment

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.