Opened 12 years ago
Last modified 5 years ago
#23902 new defect (bug)
Classes set with nav_menu_css_class are not accessible in walker_nav_menu_start_el
Reported by: | jamesmehorter | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.5.1 |
Component: | Menus | Keywords: | has-patch needs-testing needs-refresh |
Focuses: | Cc: |
Description
Hello,
If you use the filter hook nav_menu_css_class to add classes to a menu item, those classes are not available in other menu filter hooks like walker_nav_menu_start_el. This can be found in the start_el function in wp-includes/nav-menu-template.php. I would think line 75:
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) );
Should merge those $class_names back into $item.
Thanks
Attachments (1)
Change History (7)
#2
@
11 years ago
Use case:
I needed to add a little <div></div> inside menu <li>'s with the classes current-page-ancestor or current_page_parent.
If I added either of those classes manually via nav_menu_css_class, I was then unable to access those classes in the later-run walker_nav_menu_start_el hook to add the html.
(When using a page as a CPT ancestor you have to manually add the classes as mentioned above)
@ericlewis - regardless of use, a later-run hook should always have the most current object-whatever it is. Given that nav_menu_css_class runs before walker_nav_menu_start_el - any change made to the menu via nav_menu_css_class should be accessible in any later hook.
Does that help?
I don't see a utility in having the class names of the
<li>
wrapper in the args for the inner output's filter (walker_nav_menu_start_el
).@jamesmehorter can you provide a use case?