WordPress Bootstrap Navwalker
From Wiki @ Karl Jones dot com
Revision as of 09:16, 17 December 2015 by Karl Jones (Talk | contribs) (Created page with "'''WordPress Bootstrap Navwalker''' ('''wp-bootstrap-navwalker''', etc.) describes itself as "a custom WordPress nav walker class to fully implement the Bootstrap 3.0+ nav...")
WordPress Bootstrap Navwalker (wp-bootstrap-navwalker, etc.) describes itself as "a custom WordPress nav walker class to fully implement the Bootstrap 3.0+ navigation style in a custom theme using the WordPress built in menu manager."
Download
How to use
Place wp_bootstrap_navwalker.php in your WordPress theme folder /wp-content/your-theme/
Open your WordPress themes functions.php
file and add the following code:
// Register Custom Navigation Walker require_once('wp_bootstrap_navwalker.php');
Also in the functions file:
register_nav_menus( array( 'primary' => __( 'Primary Menu', 'THEMENAME' ), ) );
header.php
Update header.php
to use the walker by adding code like this:
<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>