You have to create a new navigation walker class in your theme, in which you will override the default output to match the one required by Bootstrap.
Download a drop-in nav walker class for Bootstrap here and do the following:
-
Load the new walker class in your theme’s
template.php
file:require_once(‘wp_bootstrap_navwalker.php’);
-
Create the menu in admin.
-
Use the following code to display it:
<?php wp_nav_menu( array( 'menu' => 'primary', 'theme_location' => 'primary', 'depth' => 2, 'container' => 'div', 'container_class' => 'collapse navbar-collapse navbar-ex1-collapse', 'menu_class' => 'nav navbar-nav', 'fallback_cb' => 'wp_bootstrap_navwalker::fallback', 'walker' => new wp_bootstrap_navwalker()) ); ?>
Check out also this article which explains how to do this using the same existing class for Bootstrap.