Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress From Bootstrap to WordPress Add Bootstrap Components to WordPress Theme Dropdown Bootstrap Menus and the Walker Class

Struggling to get menu to work with Walker Class

Hello

Me again - sorry! :)

I'm trying to implement the Walker Class in my site, and have tried various external tutorials - but just can't get it working.

This is what I'm doing:

Downloaded file, placed it in theme directory.

I created a new menu called "Primary" - and I set it to be the Header Menu. I added all my pages to the menu.

In functions.php I am pasting the following code at the END:

// Register Custom Navigation Walker require_once('wp_bootstrap_navwalker.php');

In header.php my code is currently as follows (no changes yet):

<div class="navbar navbar-inverse navbar-fixed-top" role="navigation"> <div class="container"> <div class="navbar-header"> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> <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 bloginfo( 'url' ); ?>"><?php bloginfo( 'name' ); ?></a> </div>

    <div class="navbar-collapse collapse">

      <?php 
        $args = array(
          'menu'        => 'header-menu',
          'menu_class'  => 'nav navbar-nav',
          'container'   => 'false'
        );
        wp_nav_menu( $args );
      ?>

    </div>

AFTER:

<?php $args = array( 'menu' => 'header-menu', 'menu_class' => 'nav navbar-nav', 'container' => 'false', 'fallback_cb' => 'wp_bootstrap_navwalker::fallback', 'walker' => new wp_bootstrap_navwalker()) ); wp_nav_menu( $args ); ?>

Would appreciate any help - thank you! :D

2 Answers

Chris Southam
Chris Southam
1,823 Points

Is "// Register Custom Navigation Walker require_once('wp_bootstrap_navwalker.php');" all on one line, or is the forum formatting a bit wonky?

No sorry, it's not on one line...