0
I have a dynamic menu in Wordpress and I’m wanting to add a function so when press the menu link it hide the entire menu on mobile. In case it would only be to take the class show from #Mainnav when clicking on a menu
$('#main-nav li a').on('click', function() {
$('#main-nav').removeClass('show');
});
<?php
wp_nav_menu(array(
'theme_location' => 'primary',
'container' => 'div',
'container_id' => 'main-nav',
'container_class' => 'collapse navbar-collapse justify-content-center',
'menu_id' => false,
'menu_class' => 'navbar-nav',
'add_li_class' => 'nav-item',
'depth' => 3,
'fallback_cb' => 'wp_bootstrap_navwalker::fallback',
'walker' => new wp_bootstrap_navwalker()
));
?>
And what’s not working?
– Sam
@Sam when I click on the 'a" link it does not remove the class.
– kaiquemix
Try:
$(document).on('click','#main-nav li a', function() {
– Sam
Vlw friend worked, I will try to find a way to pull this straight by wordpress now to stick a little more beautiful, but important that worked :)
– kaiquemix