insert an HTML element if there is a submenu only

Question

I am trying to insert an HTML element "an arrow or a checkbox" to make use of the "checkbox technique" so I can use it to expand the submenu "only if submenu is there" when checked.
my question is: how to insert this HTML element if there is a "sub-menu" class only or only when the list < li> has a class "menu-item-has-children" then insert this HTML element.

I have tried to hook on 2 filters: nav_menu_css_class and wp_nav_menu_items but didn’t succeed.

I have also tried to add this element when calling the menu:

wp_nav_menu(array(
 'theme_location' => 'main-menu',
 'depth'          => 0,
 'menu_class'     => 'topNav-List',
 'menu_id'        => 'topNL',
 'after'          => ' <label for="dropDown" class="btn-dropdown"></label>
                       <input class="dropdown-open" type="checkbox" id="dropDown"/>
                       <label for="dropDown" class="dropdown-overlay"></label>'
));

but it will add this checkbox to all list items, which I don’t want at all.

0
Moosa 2 years 2020-12-26T17:11:37-05:00 0 Answers 3 views 0

Leave an answer

Browse
Browse