I am attempting to add
onclick="toggle_visibility('sub-menu');"
into the initial tag of explicit menu things produced in WordPress. I have utilized the accompanying capacity to focus on all parent menu things and presently need to track down the right js to add this in dynamically.
function menu_set_dropdown( $sorted_menu_items, $args ) {
$last_top = 0;
foreach ( $sorted_menu_items as $key => $obj ) {
/it is a top lv thing?
on the off chance that ( 0 == $obj->menu_item_parent ) {
/set the key of the parent
$last_top = $key;
} else {
$sorted_menu_items[$last_top]- >classes['dropdown'] = 'dropdown';
}
}
return $sorted_menu_items;
}
add_filter( 'wp_nav_menu_objects', 'menu_set_dropdown', 10, 2 );
I have attempted this in my footer however it’s not working. I might be utilizing some unacceptable content, or I may not be utilizing this correctly.
<script type="text/javascript">
$('.res-clearfix li.dropdown a').click(function() {
onclick="toggle_visibility('sub-menu');"
});
</script>