├── readme.md └── wp-bootstrap-navwalker.php /readme.md: -------------------------------------------------------------------------------- 1 | wp-bootstrap-navwalker 2 | ====================== 3 | 4 | **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.** 5 | 6 | This version adds the support for multi level dropdowns with titles and descriptions. 7 | 8 | NOTE 9 | ---- 10 | This is a utility class that is intended to format your WordPress theme menu with the correct syntax and classes to utilize the Bootstrap dropdown navigation, and does not include the required Bootstrap JS files. You will have to include them manually. 11 | 12 | Installation 13 | ------------ 14 | Place **wp_bootstrap_navwalker.php** in your WordPress theme folder `/wp-content/your-theme/` 15 | 16 | Open your WordPress themes **functions.php** file `/wp-content/your-theme/functions.php` and add the following code: 17 | 18 | ```php 19 | // Register Custom Navigation Walker 20 | require_once('wp_bootstrap_navwalker.php'); 21 | ``` 22 | 23 | Usage 24 | ------------ 25 | Update your `wp_nav_menu()` function in `header.php` to use the new walker by adding a "walker" item to the wp_nav_menu array. 26 | 27 | ```php 28 | 'primary', 31 | 'depth' => 0, 32 | 'container' => '', 33 | 'menu_class' => 'nav navbar-nav', 34 | 'walker' => new BootstrapNavMenuWalker() 35 | ); 36 | wp_nav_menu($args); 37 | ?> 38 | ``` 39 | 40 | Your menu will now be formatted with the correct syntax and classes to implement Bootstrap dropdown navigation. 41 | 42 | You will also want to declare your new menu in your `functions.php` file. 43 | 44 | ```php 45 | register_nav_menus( array( 46 | 'primary' => __( 'Primary Menu', 'THEMENAME' ), 47 | ) ); 48 | ``` 49 | 50 | Typically the menu is wrapped with additional markup, here is an example of a ` navbar-fixed-top` menu that collapse for responsive navigation. 51 | 52 | ```php 53 | 80 | ``` 81 | 82 | To change your menu style add Bootstrap nav class names to the `menu_class` declaration. 83 | 84 | Review options in the Bootstrap docs for more information on nav classes 85 | http://getbootstrap.com/components/#nav 86 | 87 | Displaying the Menu 88 | ------------------- 89 | To display the menu you must associate your menu with your theme location. You can do this by selecting your theme location in the *Theme Locations* list wile editing a menu in the WordPress menu manager. 90 | 91 | Displaying the Titles and Descriptions 92 | ------------------- 93 | To display the menu item descriptions you need to click the tab **Screen Options** at the top of the screen and check "Title Attribute" and "Descriptions". The title attribute is part of the menu ite's link. the description text is not inside the menu item's link so you can add text here. 94 | 95 | 96 | 97 | Original work by johnmegahan https://gist.github.com/1597994, Emanuele 'Tex' Tessore https://gist.github.com/3765640 98 | 99 | -------------------------------------------------------------------------------- /wp-bootstrap-navwalker.php: -------------------------------------------------------------------------------- 1 | 0) ? ' sub-menu' : ''; 15 | $output .= "\n$indent