I am trying to add a div after any submenu items in a WordPress menu. I am working on the following code in the functions.php file:
add_filter( 'nav_menu_link_attributes', 'SubMenuCheck', 10, 3 );
function SubMenuCheck( $atts, $item, $args ) {
if (in_array('menu-item-has-children', $item->classes)) {
$args->after = '<div class="click">+</div>';
}
return $atts;
}
The code above adds the new div <div class="click">+</div>
but keeps applying it to all parent and child items after the first 'menu-item-has-children' class:
Does anyone know why this is repeating?... I only want the div to display for items with the menu-item-has-children
class.
Thanks