Opened 11 years ago
Last modified 5 years ago
#26935 new enhancement
Add empty submenu page to hide menu page title in list
Reported by: | josh401 | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.8 |
Component: | Menus | Keywords: | needs-patch |
Focuses: | Cc: |
Description (last modified by )
My question has to do with add_menu_page()
and add_submenu_page()
. If we add a menu page, and one sub_menu page.. we end up with the main menu page being duplicated in the sub pages list.
If we have "Main" as our main page, and "Sub" as our sub page...
add_menu_page('Main', 'Main', 'manage_options', 'main_options', array($this, 'main_do_page')); add_submenu_page('main_options', 'Sub', 'Sub', 'manage_options', 'sub_options', null);
This will create a menu structure such as:
- Main
- Main
- Sub
The "Main" page is duplicated in the sub list.
Now, we can hide that duplication with a slight adjustment to the code:
add_menu_page('Main', 'Main', 'manage_options', 'main_options', array($this, 'main_do_page')); add_submenu_page('main_options', 'Sub', 'Sub', 'manage_options', 'main_options', null);
By changing the fifth argument to match the "Main" page slug.. it will successfully hide the submenu; resulting in:
- Main
- Sub
However... the issue with this... is a menu item still gets created in the generated html. The inner html is blank.. so no title is actually displayed.. but the outer html is still there.
It appears in the submenu html output as such (with the second snippet above):
<li class="wp-first-item current"> <a class="wp-first-item current" href="admin.php?page=main_options"></a> </li> <li> <a href="admin.php?page=sub_options">Options</a> </li>
See how the top item has the html for a list item.. but has no inner html?
This creates a space, about 4 or 5 pixels.. in between the main item and the sub menu items.
Now, I know this is trivial when there is only one menu item. But, now that I know it exists.. it is driving me nuts.
- It results in unnecessary html output.
- It results in a space in the menu item list.. which is faint, but unattractive... and hinders the visual appeal of the new admin panel.
Could we perhaps first check if the add_submenu_page()
fifth argument ($menu_slug) matches the add_menu_page()
first argument ($page_title)... then the outer html wrapper doesn't get rendered?
With space example(http://joshlobe.com/testsite/images/trac1)
Without space example(http://joshlobe.com/testsite/images/trac2)
Thank you for reading.
Change History (3)
#2
@
9 years ago
- Keywords needs-patch added
- Milestone changed from Awaiting Review to Future Release
#3
@
9 years ago
Updated image links (sorry about that):
With space example: http://joshlobe.com/images/trac1.PNG
Without space example: http://joshlobe.com/images/trac2.PNG
Hi Scott, I've seen your name everywhere :) Nice to e-meet you, I'm Josh. I've never done a WP core commit; but I do have some experience with SVN and GIT. If you could point me to a "trusted" article on core committing... I'd be happy to attempt a patch for this issue.
Thank you, kindly.
Related: #19085