Wordpress - wp_nav_menu(), how to change <li> class?
Use a custom walker, remove anything you don’t need and add your classes. Here is a walker I use to get a list with clean markup: T5_Nav_Menu_Walker_Simple.
Your could also filter 'nav_menu_css_class'
or 'wp_nav_menu_items'
. But a walker class is easier to understand and to control in my opinion.
go to appearance > menus - select the menu you want - go to "screen options" at the top right, select "css classes" - add a class to each menu item..
Setting the <li>
class to nav-link
, as bootstrap 4.3 needs it:
function add_menu_link_class($atts, $item, $args)
{
$atts['class'] = 'nav-link';
return $atts;
}
add_filter('nav_menu_link_attributes', 'add_menu_link_class', 1, 3);
You can also unset the id
attribute in that array.