This snippet allows you to create Bootstrap 4 menus without the use of a Walker. Instead, we're using filters to leverage WordPress core functionality as much as possible. Basically, all you need to do is this and you're done:
<nav class="navbar navbar-expand-lg fixed-top">
<div class="container">
<a class="navbar-brand" href="<?php echo home_url(); ?>">
<?php echo bloginfo('name'); ?>
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-expanded="false" aria-controls="navbarSupportedContent" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<?php
wp_nav_menu(array(
'menu' => 'foo',
'container' => false,
'menu_id' => false,
'menu_class' => 'navbar-nav',
'bootstrap' => true
));
?>
</div>
</div>
</nav>
- Drop the PHP code below into your
functions.php
file of your theme. - Add
'bootstrap' => true
to yourwp_nav_menu
calls.
u missed current-menu-item & current-{post_type}-ancestor to active