Bootstrap Navbar under WordPress

If you’re fallen in love with Twitter Bootstrap and WordPress as I am, you’ll probably need to develop a theme with both of them and one of the first issue you will find is to have the navbar integrated with the wordpress menu managing system.

There was a nice and candy walker, written by johnmegahan that makes the hard job done in like 2 minutes of googleing πŸ™‚
Thank you John!

The limit was that it only support a double level menu. This means you can only make a dropdown, wich in BootStrap is not an anchor to a real page but only a toggler element for the openclose popup, with a list of one level.

Well to expand it is really simple: I’ve make a gist for it:

Simply copy and paste it at the end of your functions.php

As I was coding something interesting I’ve also added support for horizontal dividers element: a nice separator between two entries.
To have it simply add the class ‘divider‘ into the optional css classes field in the element of the wordpress menu.
The line will be printed before the element you gave the class.

Once registered the navbar with register_nav_menuΒ in functions.php

register_nav_menu('top-bar', __('Primary Menu'));

This is how to print the navigation bar:

This piece of code (I hope) is re-usable on every WordPress theme; it will be included in my list of everywhere present classes.
That’s all folks, let bootstrap fill your heart πŸ™‚

Update:
If you like to have the bootstrap navbar dropdown menu open on mouse over, simply use this JavaScript code somewhere after jQuery.js and bootstrap.js