Friday, December 2, 2022
HomeWordPress Developmentnavigation - Apply walker_nav_menu_start_el however solely to at least one menu

navigation – Apply walker_nav_menu_start_el however solely to at least one menu


I am constructing an accessible dropdown menu and efficiently created a button to toggle the menu for display screen readers that does not intrude with a top-level hyperlink. I focused the category menu-item-has-children to do that, and thought I used to be making use of it to just one menu, however it’s exhibiting up within the footer the place I do not need or want it. Searching for a method to solely apply this in wp_nav_menu when a selected walker is utilized.

// ADD SUBMENU BUTTON FOR A11Y
    operate test_menu_arrow($item_output, $merchandise, $depth, $args) {
    if (in_array('menu-item-has-children', $item->lessons)) {
        $aria_label = $item->title;
        $aria_controls = $item->ID;
        $arrow = '<button class="sub-menu-btn" aria-expanded="false" aria-controls="sub-menu-'.$aria_controls.'" aria-label="Extra '.$aria_label.'"></button>';
        $item_output = str_replace('</a>', '</a>'. $arrow .'', $item_output);
    }
        return $item_output;
    }
    add_filter('walker_nav_menu_start_el', 'test_menu_arrow', 10, 4);

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments