Code Food Travel repeat!

Bootstrap close Mobile / Responsive menu “on click”

This is a great snippet from stackoverflow.

The Snippet to automatically close your Boostrap Menu after clicking on an item

This is great if you are hyperlinking to jumps on the same page (ie. if you have a one-page layout).

$(function(){
	var navMain = $("#nav-main");
	navMain.on("click", "a", null, function() {
		navMain.collapse('hide');
	});
});

Then find your nav menu HTML/PHP and add label it with ID id=”nav-main”.
If you’re using Roots Theme, this is under templates/header-top-navbar.php.

Twitter Bootstrap Roots Theme

I’m using the Roots Theme, which uses Grunt to compile all the scripts.
Paste this snippet into your _main.js file into the All Pages section so it fires on all pages. My snippet above is cleaned up of any stray spaces and characters to prevent compiling errors.

About Steven Chu


Hi, I'm Steven! I'm an entrepreneur, photographer and art director in New York. Follow this blog for self expression, fun, and most importantly: looking comfortable, at ease, and amazing in your photos no matter who takes them! I dedicate this to my amazing friends who have let me inadvertently turn all of our hangouts and travel photos into a never ending photoshoot of fun. The proof is in the pudding-- our photos rock. My other projects: I'm the founder of InstaTechie.com, a face-to-face tech concierge service for NYC. Book a techie to walk you through something you want to learn! My work focuses on socially engaged art projects which use technology to create access to resources for communities. Visit Steven Chu Studio (stevenchustudio.com) for branding & design work or Steven Chu (stevenchu.com) for photography projects.

1 Comment

  1. Kevin Grube · March 22, 2015 Reply

    Awesome. LOTS of templates don’t close the mobile menu. Should be at least an option.

Leave a Reply

%d bloggers like this:
Read previous post:
Customize WordPress Google Maps Store Locator Plugin: WPSL

This is a post of all the awesome mods I was able to do on WP Store Locator to have...

Close