Thanks to the answer from the Wordpress stack, I got this solution:
add this to your functions. php
register_nav_menus(array( 'top-menu' => __('Menu1', 'twentyfourteen'), 'side-menu' => __('Menu2', 'twentyfourteen'), 'footer-menu' => __('Menu3', 'twentyfourteen') ) ); function my_walker_nav_menu_start_el($item_output, $item, $depth, $args) { $menu_locations = get_nav_menu_locations(); if ( has_term($menu_locations['top-menu'], 'nav_menu', $item) ) { $item_output = preg_replace('/<a /', '<a class="list-group" ', $item_output, 1); } return $item_output; } add_filter('walker_nav_menu_start_el', 'my_walker_nav_menu_start_el', 10, 4);
finally, you must select the “Menu1” option for the specific menu into which you need to add custom binding classes from the “Settings” panel → menu. [select menu2 or menu3 for other menus whose anchor links do not require a custom class]
To add an “active class” to the first menu item of a particular menu, try the following:
function my_walker_nav_menu_start_el($item_output, $item, $depth, $args) { $menu_locations = get_nav_menu_locations(); if ( has_term($menu_locations['top-menu'], 'nav_menu', $item) ) { $item_output = preg_replace('/<a /', '<a class="list-group" ', $item_output, 1); if ($item->menu_order == 1){ $item_output = preg_replace('/<a /', '<a class="list-group active" ', $item_output, 1); } } return $item_output; } add_filter('walker_nav_menu_start_el', 'my_walker_nav_menu_start_el', 10, 4);
if the active class should be added to the first menu item of all menus, then use this:
function my_walker_nav_menu_start_el($item_output, $item, $depth, $args) { $menu_locations = get_nav_menu_locations(); if ( has_term($menu_locations['top-menu'], 'nav_menu', $item) ) { $item_output = preg_replace('/<a /', '<a class="list-group" ', $item_output, 1); } if ($item->menu_order == 1){ $item_output = preg_replace('/<a /', '<a class="active" ', $item_output, 1); } return $item_output; } add_filter('walker_nav_menu_start_el', 'my_walker_nav_menu_start_el', 10, 4);