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 Setup a Bootstrap Theme Creating Bootstrap Navigation in WordPress

Jake Ford
Jake Ford
9,230 Points

Where does menu_class => nav navbar-nav come from? What if I wasn't using bootstrap?

I don't understand how he is linking his html to his nav function. Where is he getting nav navbar-nav for his menu_class? If we were not using bootstrap, what would we use for the menu_class value?

For instance, my navigation:

            <nav class="navbar">
              <ul class="nav">
                <li class="item">
                  <a class="item-link" href="#">JOIN NOW</a>
                </li>
                <li class="item">
                  <a class="item-link" href="#">SIGN IN</a>
                </li>
              </ul>
            </nav>

2 Answers

Tim Knight
Tim Knight
28,888 Points

This is typically what I use when I'm using the WP Bootstrap Walker:

<?php
  wp_nav_menu( array(
    'menu'              => 'primary',
    'theme_location'    => 'primary',
    'depth'             => 2,
    'container'         => 'div',
    'container_class'   => 'collapse navbar-collapse',
    'container_id'      => 'primary-nav-collapse',
    'menu_class'        => 'nav navbar-nav',
    'fallback_cb'       => 'wp_bootstrap_navwalker::fallback',
    'walker'            => new wp_bootstrap_navwalker())
  );
?>

The container_class is a div that wraps the entire navigation item where as the menu_class are the classes that are on the navigation item itself. Hopefully this will at least give you a bit more information to get things going.

Tim Knight
Tim Knight
28,888 Points

Jake,

The classes that are covered in the course are because he's using Bootstrap. If you weren't using Bootstrap you'd have to program the show/hide menu functionality yourself which could be triggered based on those class names. The "nav navbar-nav" comes specifically from Bootstrap. You can read more about those classes at http://getbootstrap.com/components/#navbar.

Jake Ford
Jake Ford
9,230 Points

But what does wordpress look for? In my example above, would I just pass the class .navbar, and wordpress would automatically get everything inside of it?

Or would I need to pass the class .nav, because it is the unordered list with all of the list items inside(Nav items)?