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
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’sfunctions.php
file, or in a.php
file of a plugin you might be writing:If you are still using WordPress 3.0 you have to
unset()
an element of the global variable$submenu
like this:Assign the first submenu slug similar to the parent menu. In your case, replace ‘job-applications’ with the slug of the main menu ‘forms’.
I had to add_submenu_page, then remove it (wp 4.0.1)
I would suggest keeping the extra menu item, becuase it’s how all the other WP menus work. (I know that’s not what you asked!…) The way the other top-level menus work is that they have different labels for the big menu title and the duplicate one below it (e.g. ‘Users’, ‘All Users’; ‘Tools’, ‘Available Tools’). I think it’s good to stick with the same paradigm, so I usually rename the first submenu item like this: