#16679 closed defect (bug) (invalid)
wp_nav_menu treats menu_class differently for fallback
Reported by: | Nonchalant | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.1 |
Component: | Menus | Keywords: | |
Focuses: | Cc: |
Description
I've found references to this issue, but no actual solution or prior ticket. Issue:
When using wp_nav_menu, the output manner of menu_class is different depending if a fallback is being used or not.
Menu:
$wp_nav_header = array( 'theme_location' => 'primaryheader', 'menu' => '', 'container' => false, 'container_class' => '', 'container_id' => '', 'menu_class' => 'sf-menu', 'menu_id' => '', 'fallback_cb' => 'wp_page_menu', 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '', 'depth' => 0,); wp_nav_menu( $wp_nav_header);
Output without Fallback (Correct output):
<ul id="menu-default" class="sf-menu"><li...
Output with Fallback (Incorrect output):
<div class="sf-menu"><ul><li...
So despite setting 'sf-menu' in menu_class, it creates a container (which I had explicitly disabled). It also does not populate the unordered list with the mentioned class.
Thank you,
Noel
Change History (6)
#1
follow-up:
↓ 2
@
14 years ago
- Keywords close added; needs-testing removed
- Milestone changed from Awaiting Review to Future Release
#2
in reply to:
↑ 1
@
14 years ago
- Resolution set to fixed
- Status changed from new to closed
Replying to filosofo:
The
<div>
element is being generated by your fallback, in this casewp_page_menu
. You can expect the markup to vary from non-fallback to the extent that the fallback differs, andwp_page_menu
does not have an argument to remove the wrapping<div>
element.
Some possible ways to address this:
- Use a fallback of your own creation that more closely resembles typical menu markup.
- Open a ticket to make
wp_page_menu
to print markup more like standardwp_nav_menu
.
Thank you for the explanation! I tried looking through the Codex too and hence was stumped by this. What I'll do is make a codex contribution once I've created a fallback of my own creation.
The
<div>
element is being generated by your fallback, in this casewp_page_menu
. You can expect the markup to vary from non-fallback to the extent that the fallback differs, andwp_page_menu
does not have an argument to remove the wrapping<div>
element.Some possible ways to address this:
wp_page_menu
to print markup more like standardwp_nav_menu
.