#16679 closed defect (bug) (invalid)
wp_nav_menu treats menu_class differently for fallback
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Menus | Version: | 3.1 |
| Severity: | normal | Keywords: | |
| 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)
- Keywords close added; needs-testing removed
- Milestone changed from Awaiting Review to Future Release
comment:2
in reply to:
↑ 1
Nonchalant — 2 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 case wp_page_menu. You can expect the markup to vary from non-fallback to the extent that the fallback differs, and wp_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 standard wp_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.
- Keywords close removed
- Resolution fixed deleted
- Status changed from closed to reopened
Thanks for improving the Codex. I'm sure others will benefit from the explanation.
comment:6
SergeyBiryukov — 6 hours ago
Related: #18842

The <div> element is being generated by your fallback, in this case wp_page_menu. You can expect the markup to vary from non-fallback to the extent that the fallback differs, and wp_page_menu does not have an argument to remove the wrapping <div> element.
Some possible ways to address this: