I am trying to add a class to the default ul generated in a custom wordpress menu.
I have created the custom menu in the backend and set it up fine, after referencing the wordpress codex this is the code I am currently using:
<?php
if ( has_nav_menu( 'main-navigation' ) ) { /* if menu location 'main-navigation' exists then use custom menu */
wp_nav_menu(
array(
'theme_location' => 'Main Navigation',
'menu_class' => 'row',
'items_wrap' => '<ul class="nav">%3$s</ul>',
'walker' => '',
)
);
}
?>
This is generating a div with a class of “row” wrapping around my ul but no class is added to the ul itself. I have seen many people with this problem online but no solutions.
Thanks.
You can achieve this with jQuery by targetting the ul element and adding a class like this:
$(“.row ul”).addClass( “CLASS-HERE” );
Try this extension from GitHub. It allows you to use Bootstrap navigation components in WordPress with easy.
https://github.com/twittem/wp-bootstrap-navwalker
you can use parameter