I'm trying to setup a Bootstrap 4 navbar menu but I can't get it to work the way I wanted.
The new Bootstrap 4 navbar menu code looks like this.
<nav class="navbar navbar-expand-lg navbar-dark bg-success">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
<div class="navbar-nav mr-auto">
<a class="nav-item nav-link active" href="#">Home <span class="sr-only">(current)</span></a>
<a class="nav-item nav-link" href="#our-company">Our Company</a>
<a class="nav-item nav-link" href="#our-products">Products</a>
</div>
<div class="navbar-nav">
<a class="nav-item nav-link" href="#"><i class="fa fa-envelope mr-2"></i>[email protected]</a>
<a class="nav-item nav-link" href="#"><i class="fa fa-phone mr-2"></i>+1-234-567-8910</a>
</div>
</div>
</nav>
Note, the nav-items are enclosed by a div with a class of navbar-nav which is also enclosed with a parent div with class of collapse navbar-collapse. It's outermost parent div is nav with a class of navbar.
The WordPress way of displaying the menu on the other hand looks like this.
<div class="menu-main-menu-container">
<ul id="menu-main-menu" class="menu">
<li id="menu-item-11" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-11">
<a href="#">Home</a>
</li>
<li id="menu-item-12" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-12">
<a href="#our-company">Our Company</a>
</li>
<li id="menu-item-13" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-13">
<a href="#our-products">Our Products</a>
</li>
</ul>
</div>
WordPress does the menu using ul and li. Whereas Bootstrap does it via divs and anchor tags.
My WordPress way of coding the menu looks like this below:
<?php
wp_nav_menu([
'theme_location' => 'primary',
'container' => 'div',
'container_id' => '',
'container_class' => 'collapse navbar-collapse',
'menu_class' => 'navbar-nav mr-auto',
]);
?>
Now, when the menu gets generated, it looked like this on the site.
<div class="navbar-nav mr-auto">
<ul>
<li class="page_item page-item-7 current_page_item">
<a href="http://localhost/envirodyn/" aria-current="page">Home</a>
</li>
</ul>
</div>
If that is how WordPress does it, then at least I wanted to be able to add a class .navbar-nav to the ul, .nav-item to the li tag, .nav-link to the anchor tag.
That way, it would look like this
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link">Menu 1</a>
</li>
<li class="nav-item">
<a class="nav-link">Menu 2</a>
</li>
</ul>