wp-bootstrap / wp-bootstrap-navwalker

A custom WordPress nav walker class to fully implement the Twitter Bootstrap 4.0+ navigation style (v3-branch available for Bootstrap 3) in a custom theme using the WordPress built in menu manager.
https://wp-bootstrap.github.io/wp-bootstrap-navwalker/
GNU General Public License v3.0
3.37k stars 1.94k forks source link

Mobile menu not working #493

Closed liukang93 closed 3 years ago

liukang93 commented 4 years ago

Steps to reproduce the issue:

``

        <div class="collapse navbar-collapse content" id="collapsibleNavbar">
        Hello
            <?php
            wp_nav_menu( array(
                'theme_location'    => 'top-menu',
                'depth'             => 2,
                'container'         => 'div',
                'container_class'   => 'collapse navbar-collapse collapse',
                'container_id'      => 'bs-example-navbar-collapse-1',
                'menu_class'        => 'navbar-nav ml-auto',
                'menu_id'           => 'navbar-content',
                'fallback_cb'       => 'WP_Bootstrap_Navwalker::fallback',
                'walker'            => new WP_Bootstrap_Navwalker(),
            ) );
            ?>
            World
        </div>

``

What I expected:

Showing when site is on mobile

What happened instead:

Hello World is displayed but the dynamic content did not display.

IanDelMar commented 3 years ago

Hi @liukang93, try this

<button class="navbar-toggler collapsed" type="button" data-toggle="collapse" data-target="#collapsibleNavbar" aria-controls="collapsibleNavbar" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse content" id="collapsibleNavbar">
    Hello
    <?php
    wp_nav_menu(
        array(
            'theme_location' => 'top-menu',
            'depth'                => 2,
            'menu_class'       => 'navbar-nav ml-auto',
            'menu_id'            => 'navbar-content',
            'fallback_cb'        => 'WP_Bootstrap_Navwalker::fallback'
            'walker'               => new WP_Bootstrap_Navwalker(),
        )
    ); ?>
    World
</div>

and make sure a menu is assigned to the menu location 'top-menu'.

Please let me know whether this worked for you.

jamesjsewell commented 3 years ago

i'm experiencing the same issue, tried this solution with no luck. the menu remains display: none, even after onclick, also the active link isn't highlighted. I dont think this is a wordpress js issue as the modal works fine. could it be my version of bootsrap?

IanDelMar commented 3 years ago

@jamesjsewell please provide your code.

jamesjsewell commented 3 years ago

@IanDelMar thanks i just figured it out, for me i was using bootstrap 5, DOH! going back to bs4 resolved the issues. see https://github.com/wp-bootstrap/wp-bootstrap-navwalker/issues/499

dgdb1 commented 3 years ago

Steps to reproduce the issue:

<button class="navbar-toggler collapsed" type="button" data-toggle="collapse" data-target="#collapsibleNavbar" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse content" id="collapsibleNavbar"> Hello <?php wp_nav_menu( array( 'theme_location' => 'top-menu', 'depth' => 2, 'container' => 'div', 'container_class' => 'collapse navbar-collapse collapse', 'container_id' => 'bs-example-navbar-collapse-1', 'menu_class' => 'navbar-nav ml-auto', 'menu_id' => 'navbar-content', 'fallback_cb' => 'WP_Bootstrap_Navwalker::fallback', 'walker' => new WP_Bootstrap_Navwalker(), ) ); ?> World </div>

What I expected:

Showing when site is on mobile

What happened instead:

Hello World is displayed but the dynamic content did not display.

I tested your code and you just need to make some minor changes to make it work with Bootstrap 5.

Change:

Full work code with Bootrstrap 5:

<button class="navbar-toggler collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapsibleNavbar" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse content" id="collapsibleNavbar"> Hello 
<?php wp_nav_menu( array( 

 'theme_location'    => 'primary',
'depth'             => 2,
            'container'         => 'div',
            'container_class'   => '',
            'container_id'      => 'bs-example-navbar-collapse-1',
            'menu_class'        => 'navbar-nav ms-auto',
            'fallback_cb'       => 'WP_Bootstrap_Navwalker::fallback',
            'walker'            => new WP_Bootstrap_Navwalker(),
 ) );
?> World </div>

</header>
IanDelMar commented 3 years ago

Closing this as the issue is resolved.