X

How to Create a Responsive WordPress Menu Using Bootstrap Nav Walker

Snippets by IsItWP

Are you looking for a way to start with a responsive navigation menu using Bootstrap? While there’s probably a plugin for this, we have created a quick code snippet that you can use to completely create a responsive WordPress menu using Bootstrap nav walker in WordPress.

Instructions:

First you need to download the wp_bootstrap_navwalker.php file from here and upload it to wp-content/themes/your-theme folder.

After that, you need to add this code to your theme’s functions.php file or in a site-specific plugin:


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

Next, you need to create a Bootstrap menu and and add the following code to the header.php file of your theme.

// Create navigation
<div class="navbar " role="navigation">
            <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>
	        </div>
	
		    <div class="navbar-collapse collapse ">
				<?php  /* menu */
			       	wp_nav_menu( array(
							    'menu'              => 'primary-menu',
			       				'theme_location'    => 'primary-menu',
				        		'depth'             => 5,
				        		'container'         => 'div',
				        		'container_class'   => 'collapse navbar-collapse navbar-ex1-collapse ',
				        		'menu_class'        => 'nav navbar-nav  ',
				        		'fallback_cb'       => 'wp_bootstrap_navwalker::fallback',
				        		'walker'            => new wp_bootstrap_navwalker())
					); 
				 ?>
           	</div>
		</div><!--	Navigation -->


?>

Make sure to replace the ‘menu’ parameter with the name of your Bootstrap menu.

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly add code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: 50+ best responsive WordPress themes to create a mobile ready site and how to create a job application form in WordPress.

Comments   Leave a Reply

  1. hi
    github link not found!

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!