Opened 22 months ago
Last modified 10 months ago
#18232 new defect (bug)
wp_nav_menu - Setting walker parameter affects fallback_cb
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Menus | Version: | 3.2.1 |
| Severity: | normal | Keywords: | has-patch needs-testing |
| Cc: | marko@…, BenjaminRMueller |
Description
When using the walker parameter with wp_nav_menu and there is no menu present, wp_nav_menu falls back by default (set with fallback_cb) to wp_page_menu. It appears that the set walker also affects wp_page_menu, which in most cases breaks the output.
wp_nav_menu usage:
<?php wp_nav_menu(array('walker'=> new Walker_Nav_Menu)); ?>
Output when no menu is present (falling back on wp_page_menu):
// Formatted for readability <div class="menu"> <ul> <li id="menu-item-1" class="menu-item-1"><a></a></li> <li id="menu-item-2" class="menu-item-2"><a></a></li> <li id="menu-item-3" class="menu-item-3"><a></a></li> </ul> </div>
Expected output:
// Formatted for readability <div class="menu"> <ul> <li class="page_item page-item-1"><a href="/first/" title="First">First</a></li> <li class="page_item page-item-2"><a href="/second/" title="Second">Second</a></li> <li class="page_item page-item-3"><a href="/third/" title="Third">Third</a></li> </ul> </div>
As you can see, the output from wp_page_menu is getting filtered through the walker, but since the walker was designed for menus specifically, it renders the default output from wp_page_menu useless (empty tags..etc).
Attachments (2)
Change History (6)
SergeyBiryukov — 22 months ago
comment:1
SergeyBiryukov — 22 months ago
- Keywords has-patch added; needs-patch removed
comment:2
bryanjwatson — 22 months ago
- Keywords needs-testing added
- Summary changed from wp_nav_menu - Setting walker parameter affects fallback_cb (wp_page_menu) to wp_nav_menu - Setting walker parameter affects fallback_cb
bryanjwatson — 22 months ago
comment:3
markoheijnen — 16 months ago
- Cc marko@… added
Is it really necessary to have special arguments for the fallback only for the walker? I rather would create a parameter only for setting the walker for the fallback.
- Cc BenjaminRMueller added

Simple patch, but unfortunately it does not account for the scenario when a function other than wp_page_menu is set as the fallback_cb parameter.
For example, this would still break:
<?php wp_nav_menu(array('fallback_cb'=>'wp_list_categories','walker'=>new Walker_Nav_Menu)); ?>I believe the issue resides in the fact that the fallback function is inheriting the $args passed to wp_nav_menu.
Solution: Stop the $args inheritance on the fallback function, and create a new wp_nav_menu parameter to provide custom fallback args if needed. See patch 18232_v2.