Add name of parent li to submenu ul as id (walker_nav_menu)
-
Hello, I’m building my own theme with a custom nav menu which extends the walker_nav_menu.
I use the code below in my functions.php. All it does is remove the standard id’s and classes. And add a ‘dropdown arrow’ icon for each submenu.
How can I add the parent name as an id to the dropdown ul?
add_filter('nav_menu_css_class', 'my_css_attributes_filter', 100, 1); add_filter('nav_menu_item_id', 'my_css_attributes_filter', 100, 1); add_filter('page_css_class', 'my_css_attributes_filter', 100, 1); function my_css_attributes_filter($var) { return is_array($var) ? array_intersect($var, array('current-menu-item')) : ''; } class custom_menu extends Walker_Nav_Menu { function start_lvl(&$output, $depth) { $output .= '<i class="fa fa-angle-down" aria-hidden="true"></i><ul id="'.$args->parent_id.'">'; } function end_lvl(&$output, $depth) { $output .= '</ul>'; } }
Hope someone can help me, thanks.
– Thierry
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Add name of parent li to submenu ul as id (walker_nav_menu)’ is closed to new replies.