1

I am creating a bootstrap wordpress theme from scratch, i want to create a nav menu using WordPress nav walker class, i followed the documentation on GitHub to install it, then i added a primary menu to my wordpress theme, i chose the menu location but the navbar won't display, all i have is the navbar brand going in the center. enter image description here my header.php code:

<div class="blog-masthead">
      <div class="container">
        <nav class="navbar navbar-default" role="navigation">
  <div class="container-fluid">
    <!-- 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>
      <a class="navbar-brand" href="<?php echo home_url(); ?>">
                <?php bloginfo('name'); ?>
            </a>
    </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>

      </div>
    </div>

functions.php

<?php
    require_once('wp-bootstrap-navwalker.php');

    function wpb_theme_setup(){
        register_nav_menus( array(
        'primary' => __( 'Primary Menu', 'wpbootstrap' ),
) );
    }

    add_action('after_setup_theme', 'wpb_theme_setup');

Can anyone help me solve this?

1

I use it this way. I have never encountered any problems.

Bootstrap 3.x Navigation with dropdown for wordpress.

<nav class="navbar navbar-default">
<div class="navbar-header">
    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-navbar-collapse" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
    </button>
    <a class="navbar-brand visible-xs" href="#">MENU</a>
</div>

<div class="collapse navbar-collapse" id="bs-navbar-collapse">
    <?php
        wp_nav_menu( array(
            'theme_location'    => 'primary',
            'depth'             => 2,
            'container'         => '',
            'menu_class'        => 'nav navbar-nav',
            'fallback_cb'       => 'wp_bootstrap_navwalker::fallback',
            'walker'            => new wp_bootstrap_navwalker())
        );
    ?>
    <ul class="nav navbar-nav navbar-right">
        <?php if ( is_user_logged_in() ) { ?>
        <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><i class="fa fa-user-plus" aria-hidden="true"></i> HESABIM <span class="caret"></span></a>
            <ul class="dropdown-menu">
                <?php foreach ( wc_get_account_menu_items() as $endpoint => $label ) : ?>
                <li><a href="<?php echo esc_url( wc_get_account_endpoint_url( $endpoint ) ); ?>"><?php echo esc_html( $label ); ?></a></li>                             
                <?php endforeach; ?>
            </ul>
        </li>
        <?php } else { ?>
        <li><a href="<?php echo get_permalink( get_option('woocommerce_myaccount_page_id') ); ?>" title="Üye Ol / Giriş Yap">Üye Ol / Giriş Yap</a></li>
        <?php } ?>
    </ul>
</div>

Navigation Only;

<div class="collapse navbar-collapse" id="bs-navbar-collapse">
<?php
    wp_nav_menu( array(
        'theme_location'    => 'primary',
        'depth'             => 2,
        'container'         => '',
        'menu_class'        => 'nav navbar-nav',
        'fallback_cb'       => 'wp_bootstrap_navwalker::fallback',
        'walker'            => new wp_bootstrap_navwalker())
    );
?>
</div>
  • I tried this it worked for me but it's showing me just the links without style even though i adde the class – Pain Aug 28 '17 at 18:52
  • Edited my answer. – sakarya Aug 28 '17 at 20:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.