The “Click Event Behaviour” option (previously called “Second Click Behaviour”) is set for each menu location individually, so no code is needed to change it for a single location.
Go to Mega Menu > Menu Locations, click the menu location you want to change and go to the Advanced tab. The “Click Event Behaviour” option has three settings:
- First click will open the sub menu, second click will close the sub menu.
- First click will open the sub menu, second click will follow the link.
- First click will follow the link (the arrow must be used to toggle sub menu visibility).
This option applies when the Event is set to “Click”, and also to the mobile menu.
Using code
If you prefer to set the behaviour in code, add the following to your theme’s functions.php file:
|
1 2 3 4 5 6 7 8 |
function megamenu_second_click_one_menu_location_only($attributes, $menu_id, $menu_settings, $settings, $current_theme_location) { // change ‘primary’ to the ID of your menu location if ($current_theme_location == ‘primary’) { $attributes[‘data-second-click’] = ‘go’; // ‘go’, ‘close’ or ‘disabled’ } return $attributes; } add_filter(‘megamenu_wrap_attributes’, ‘megamenu_second_click_one_menu_location_only’, 10, 5); |