Here i have built in a Bootstrap 3 navbar in wordpress with a commom navwalker. It should collapse when the grid-breakpoint is reached. But it shows a unexpected behaviour in the way that it shows the toggle content before the button was clicked and without the right style.
The bs collapse plugin is present. And it worked some changes before, but i made failure somewhere.
I would be thankful for your help. Here is my code:
<div id="twitterbootstrap">
<nav class="navbar navbar-default <?php if ( !(is_front_page())): echo "navbar-fixed-top"; endif; ?>" role="navigation">
<div class="container" style="padding: 0;">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<?php
wp_nav_menu( array(
'menu' => 'primary',
'theme_location' => 'primary',
'depth' => 2,
'container' => 'div',
'container_class' => 'collapse navbar-collapse',
'container_id' => 'bs-example-navbar-collapse-1',
'menu_class' => 'nav navbar-nav',
'fallback_cb' => 'wp_bootstrap_navwalker::fallback',
'walker' => new wp_bootstrap_navwalker())
);
?>
</div>
</nav>
Fixed the problem:
and when the menu is expanded:
The problem here is that you are overwriting bootstrap’s default styles in your
theme.css
file, particularlytheme.css line: 187
:and
theme.css line: 207
remove those two and you are good to go.
I’ve noticed a couple of issues here, and of what I’ve messed up with Firebug so far, I’ve reached to the point where the contents of the collapse menu are not showing before the button is actually being pressed.
This I achieved by taking off the
display: inline-block !important;
from.navbar-default, .navbar .navbar-nav, .navbar-collapse
.There is still some strange issue with the collapsing menu, since it gets smacked flat right after the collapse effect actually happens. Trying to figure it out, notify me if you’re faster than me!