You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+56-48Lines changed: 56 additions & 48 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,15 +18,15 @@ This is a utility class that is intended to format your WordPress theme menu wit
18
18
19
19
*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.
20
20
21
-
### UPGRADE NOTES ###
21
+
### Upgrade Notes
22
22
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>
24
24
25
25
Here is a list of the most notable changes:
26
26
27
27
- 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`
30
30
- Icon and link modifier handling is now done through the `CSS Classes` menu item input instead of the `Title` input.
31
31
- Icon only items are possible using icon classes in combination with the `sr-only` classname.
32
32
@@ -37,78 +37,84 @@ Place **class-wp-bootstrap-navwalker.php** in your WordPress theme folder `/wp-c
37
37
Open your WordPress themes **functions.php** file - `/wp-content/your-theme/functions.php` - and add the following code:
If you encounter errors with the above code use a check like this to return clean errors to help diagnose the problem.
45
50
46
51
```php
47
52
if ( ! file_exists( get_template_directory() . '/class-wp-bootstrap-navwalker.php' ) ) {
48
-
// file does not exist... return an error.
49
-
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' ) );
You will also need to declare a new menu in your `functions.php` file if one doesn't already exist.
56
62
57
63
```php
58
64
register_nav_menus( array(
59
-
'primary' => __( 'Primary Menu', 'THEMENAME' ),
65
+
'primary' => __( 'Primary Menu', 'THEMENAME' ),
60
66
) );
61
67
```
68
+
62
69
## Usage
63
70
64
71
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.
65
72
66
73
```php
67
74
wp_nav_menu( array(
68
-
'theme_location' => 'primary',
69
-
'depth' => 2, // 1 = no dropdowns, 2 = with dropdowns.
Your menu will now be formatted with the correct syntax and classes to implement Bootstrap dropdown navigation.
80
87
81
-
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.
To change your menu style add Bootstrap nav class names to the `menu_class` declaration.
108
115
109
116
Review options in the Bootstrap docs for more information on [nav classes](https://getbootstrap.com/components/#nav).
110
117
111
-
112
118
### Displaying the Menu
113
119
114
120
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.
@@ -119,12 +125,13 @@ There has been some interest in making this walker the default walker for all me
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.
129
136
130
137
### Menu Caching
@@ -133,31 +140,32 @@ On some sites generating a large menu that rarely ever changes on every page req
133
140
134
141
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.
135
142
136
-
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/>
137
144
138
145
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.
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).
147
155
148
156
#### Icons
149
157
150
-
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`.
151
159
152
160
#### Icon-Only Items
153
161
154
162
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.
155
163
156
164
#### Disabled Links
157
165
158
-
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._
#### Dropdown Headers, Dropdown Dividers & Dropdown Item Text
161
169
162
170
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._
* Description: A custom WordPress nav walker class to implement the Bootstrap 4 navigation style in a custom theme using the WordPress built in menu manager.
13
11
* Author: Edward McIntyre - @twittem, WP Bootstrap, William Patton - @pattonwebz
0 commit comments