Skip to content

Commit 4b18b35

Browse files
committed
Merge branch 'maxwelljordanwhite-maxwelljordanwhite-patch-1'
2 parents c4109a4 + f2dcefb commit 4b18b35

File tree

1 file changed

+49
-46
lines changed

1 file changed

+49
-46
lines changed

README.md

Lines changed: 49 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ This is a utility class that is intended to format your WordPress theme menu wit
1818

1919
*This walker is fully compliant with all Theme Review guidelines for wordpress.org theme submission.* It requires no modification to be compliant but you can optionally replace the `wp-bootstrap-navwalker` text domain (which appears twice in the `fallback` function) with the text domain of your theme.
2020

21-
### UPGRADE NOTES ###
21+
### Upgrade Notes
2222

23-
Between version 3 and version 4 of the walker there have been significant changes to the codebase. Version 4 of the walker is built to work with Bootstrap 4 and has not been tested for backwards compatibility with Bootstrap 3. A separate branch for Bootstrap 3 is maintained here: https://github.com/wp-bootstrap/wp-bootstrap-navwalker/tree/v3-branch
23+
Between version 3 and version 4 of the walker there have been significant changes to the codebase. Version 4 of the walker is built to work with Bootstrap 4 and has not been tested for backwards compatibility with Bootstrap 3. A separate branch for Bootstrap 3 is maintained here: <https://github.com/wp-bootstrap/wp-bootstrap-navwalker/tree/v3-branch>
2424

2525
Here is a list of the most notable changes:
2626

2727
- The filename has been changed and prefixed with `class-` to better fit PHP coding standards naming conventions.
28-
- New Name: `class-wp-bootstrap-navwalker.php`
29-
- Old Name: `wp-bootstrap-navwalker.php`
28+
- New Name: `class-wp-bootstrap-navwalker.php`
29+
- Old Name: `wp-bootstrap-navwalker.php`
3030
- Icon and link modifier handling is now done through the `CSS Classes` menu item input instead of the `Title` input.
3131
- Icon only items are possible using icon classes in combination with the `sr-only` classname.
3232

@@ -50,70 +50,71 @@ If you encounter errors with the above code use a check like this to return clea
5050

5151
```php
5252
if ( ! file_exists( get_template_directory() . '/class-wp-bootstrap-navwalker.php' ) ) {
53-
// file does not exist... return an error.
54-
return new WP_Error( 'class-wp-bootstrap-navwalker-missing', __( 'It appears the class-wp-bootstrap-navwalker.php file may be missing.', 'wp-bootstrap-navwalker' ) );
53+
// File does not exist... return an error.
54+
return new WP_Error( 'class-wp-bootstrap-navwalker-missing', __( 'It appears the class-wp-bootstrap-navwalker.php file may be missing.', 'wp-bootstrap-navwalker' ) );
5555
} else {
56-
// file exists... require it.
57-
require_once get_template_directory() . '/class-wp-bootstrap-navwalker.php';
56+
// File exists... require it.
57+
require_once get_template_directory() . '/class-wp-bootstrap-navwalker.php';
5858
}
5959
```
60+
6061
You will also need to declare a new menu in your `functions.php` file if one doesn't already exist.
6162

6263
```php
6364
register_nav_menus( array(
64-
'primary' => __( 'Primary Menu', 'THEMENAME' ),
65+
'primary' => __( 'Primary Menu', 'THEMENAME' ),
6566
) );
6667
```
68+
6769
## Usage
6870

6971
Add or update any `wp_nav_menu()` functions in your theme (often found in `header.php`) to use the new walker by adding a `'walker'` item to the wp_nav_menu args array.
7072

7173
```php
7274
wp_nav_menu( array(
73-
'theme_location' => 'primary',
74-
'depth' => 2, // 1 = no dropdowns, 2 = with dropdowns.
75-
'container' => 'div',
76-
'container_class' => 'collapse navbar-collapse',
77-
'container_id' => 'bs-example-navbar-collapse-1',
78-
'menu_class' => 'navbar-nav mr-auto',
79-
'fallback_cb' => 'WP_Bootstrap_Navwalker::fallback',
80-
'walker' => new WP_Bootstrap_Navwalker(),
75+
'theme_location' => 'primary',
76+
'depth' => 2, // 1 = no dropdowns, 2 = with dropdowns.
77+
'container' => 'div',
78+
'container_class' => 'collapse navbar-collapse',
79+
'container_id' => 'bs-example-navbar-collapse-1',
80+
'menu_class' => 'navbar-nav mr-auto',
81+
'fallback_cb' => 'WP_Bootstrap_Navwalker::fallback',
82+
'walker' => new WP_Bootstrap_Navwalker(),
8183
) );
8284
```
8385

8486
Your menu will now be formatted with the correct syntax and classes to implement Bootstrap dropdown navigation.
8587

86-
Typically the menu is wrapped with additional markup, here is an example of a ` fixed-top` menu that collapse for responsive navigation at the md breakpoint.
88+
Typically the menu is wrapped with additional markup, here is an example of a `fixed-top` menu that collapse for responsive navigation at the md breakpoint.
8789

8890
```php
8991
<nav class="navbar navbar-expand-md navbar-light bg-light" role="navigation">
9092
<div class="container">
91-
<!-- Brand and toggle get grouped for better mobile display -->
92-
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-controls="bs-example-navbar-collapse-1" aria-expanded="false" aria-label="Toggle navigation">
93-
<span class="navbar-toggler-icon"></span>
94-
</button>
95-
<a class="navbar-brand" href="#">Navbar</a>
96-
<?php
97-
wp_nav_menu( array(
98-
'theme_location' => 'primary',
99-
'depth' => 2,
100-
'container' => 'div',
101-
'container_class' => 'collapse navbar-collapse',
102-
'container_id' => 'bs-example-navbar-collapse-1',
103-
'menu_class' => 'nav navbar-nav',
104-
'fallback_cb' => 'WP_Bootstrap_Navwalker::fallback',
105-
'walker' => new WP_Bootstrap_Navwalker(),
106-
) );
107-
?>
108-
</div>
93+
<!-- Brand and toggle get grouped for better mobile display -->
94+
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-controls="bs-example-navbar-collapse-1" aria-expanded="false" aria-label="Toggle navigation">
95+
<span class="navbar-toggler-icon"></span>
96+
</button>
97+
<a class="navbar-brand" href="#">Navbar</a>
98+
<?php
99+
wp_nav_menu( array(
100+
'theme_location' => 'primary',
101+
'depth' => 2,
102+
'container' => 'div',
103+
'container_class' => 'collapse navbar-collapse',
104+
'container_id' => 'bs-example-navbar-collapse-1',
105+
'menu_class' => 'nav navbar-nav',
106+
'fallback_cb' => 'WP_Bootstrap_Navwalker::fallback',
107+
'walker' => new WP_Bootstrap_Navwalker(),
108+
) );
109+
?>
110+
</div>
109111
</nav>
110112
```
111113

112114
To change your menu style add Bootstrap nav class names to the `menu_class` declaration.
113115

114116
Review options in the Bootstrap docs for more information on [nav classes](https://getbootstrap.com/components/#nav).
115117

116-
117118
### Displaying the Menu
118119

119120
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 while editing a menu in the WordPress menu manager.
@@ -124,12 +125,13 @@ There has been some interest in making this walker the default walker for all me
124125

125126
```php
126127
function prefix_modify_nav_menu_args( $args ) {
127-
return array_merge( $args, array(
128-
'walker' => WP_Bootstrap_Navwalker(),
129-
) );
128+
return array_merge( $args, array(
129+
'walker' => WP_Bootstrap_Navwalker(),
130+
) );
130131
}
131132
add_filter( 'wp_nav_menu_args', 'prefix_modify_nav_menu_args' );
132133
```
134+
133135
Simply updating the walker may not be enough to get menus working right, you may need to add wrappers or additional classes, you can do that via the above function as well.
134136

135137
### Menu Caching
@@ -138,31 +140,32 @@ On some sites generating a large menu that rarely ever changes on every page req
138140

139141
The biggest drawback to caching nav menus with this method is that it cannot easily apply the `.current-menu-item` or the `.active` class to the currently active item as WP decides what is currently active on page load - and since the menu is cached it only knows the active page that it was cached on originally.
140142

141-
You can decide yourself if you want to put up with those drawbacks for the benefit of removing the menu generation time on most page loads. You can follow this article by Dave Clements to see how we cached nav menus that were generated by this walker: https://www.doitwithwp.com/use-transients-speed-wordpress-menus/
143+
You can decide yourself if you want to put up with those drawbacks for the benefit of removing the menu generation time on most page loads. You can follow this article by Dave Clements to see how we cached nav menus that were generated by this walker: <https://www.doitwithwp.com/use-transients-speed-wordpress-menus/>
142144

143145
Be sure to set the `echo` argument to FALSE in `the wp_nav_menu()` call when doing this so that the results can be stored instead of echoed to the page.
144146

145147
See also:
146-
- https://generatewp.com/how-to-use-transients-to-speed-up-wordpress-menus/
147-
- https://vip-svn.wordpress.com/plugins/cache-nav-menu/cache-nav-menu.php
148+
149+
- <https://generatewp.com/how-to-use-transients-to-speed-up-wordpress-menus/>
150+
- <https://vip-svn.wordpress.com/plugins/cache-nav-menu/cache-nav-menu.php>
148151

149152
### Extras
150153

151154
This script included the ability to use Bootstrap nav link mods in your menus through the WordPress menu UI. Disabled links, dropdown headers and dropdown dividers are supported. Additionally icon support is built-in for Glyphicons and Font Awesome (note: you will need to include the icon stylesheets or assets separately).
152155

153156
#### Icons
154157

155-
To add an Icon to your link simply enter Glypicons or Font Awesome class names in the links **CSS Classes** field in the Menu UI and the walker class will do the rest. IE `glyphicons glyphicons-bullhorn` or `fa fa-arrow-left` or `fas fa-arrow-left`.
158+
To add an Icon to your link simply enter Glyphicons or Font Awesome class names in the links **CSS Classes** field in the Menu UI and the walker class will do the rest. IE `glyphicons glyphicons-bullhorn` or `fa fa-arrow-left` or `fas fa-arrow-left`.
156159

157160
#### Icon-Only Items
158161

159162
To make an item appear with the icon only apply the bootstrap screen reader class `sr-only` to the item alongside any icon classnames. This will then hide only the text that would appear as the link text.
160163

161164
#### Disabled Links
162165

163-
To set a disabled link simply add `disabled` to the **CSS Classes** field in the Menu UI and the walker class will do the rest. _Note: In addition to adding the .disabled class this will change the link `href` to `#` as well so that it is not a followable link._
166+
To set a disabled link simply add `disabled` to the **CSS Classes** field in the Menu UI and the walker class will do the rest. _Note: In addition to adding the .disabled class this will change the link `href` to `#` as well so that it is not a follow-able link._
164167

165-
#### Dropdown Headers, Dropdown Dividers & Dropdown Item Text.
168+
#### Dropdown Headers, Dropdown Dividers & Dropdown Item Text
166169

167170
Headers, dividers and text only items can be added within dropdowns by adding a Custom Link and adding either `dropdown-header`, `dropdown-divider` or `dropdown-item-text` into the **CSS Classes** input. _Note: This will remove the `href` on the item and change it to either a `<span>` for headers or a `<div>` for dividers._
168171

0 commit comments

Comments
 (0)