Content |
Deleted: | Added: <a href="https:/ /gist.github.com/ thomasgriffin/4253190" target="_blank" >https://gist.github.com/ thomasgriffin/4253190</a> |
| Added: Below is the code to do this programatically, it is worth noting that you can add classes via the menus page in the wp-admin by selecting Screen Options and then CSS Classes. The below code may be better for instances where you don't want to depend on users to remember to add the classes manually. |
Unchanged: [php] | Unchanged: [php] |
Deleted: <div id="file- gistfile1-php- LC1">add_filter( 'wp_nav_menu_objects', 'tgm_filter_menu_class' );</div>
| Added: add_filter( 'wp_nav_menu_objects', 'tgm_filter_menu_class' );
|
Deleted: <div id="file- gistfile1-php- LC2"> /**</div> | |
| Added: /** |
Deleted: <div id="file- gistfile1-php- LC3">* Filters the first and last nav menu objects in your menus</div>
| Added: * Filters the first and last nav menu objects in your menus
|
Deleted: <div id="file- gistfile1-php- LC4">* to add custom classes.</div> | |
Deleted: <div id="file- gistfile1-php- LC5"> *</div> | |
Deleted: <div id="file- gistfile1-php- LC6">* @since 1.0.0</div> | |
Deleted: <div id="file- gistfile1-php- LC7"> *</div> | |
Deleted: <div id="file- gistfile1-php- LC8">* @param object $objects An array of nav menu objects</div> | |
| Added: * to add custom classes. |
| Added: * |
| Added: * @since 1.0.0 |
| Added: * |
| Added: * @param object $objects An array of nav menu objects |
Deleted: <div id="file- gistfile1-php- LC9">* @return object $objects Amended array of nav menu objects with new class</div>
| Added: * @return object $objects Amended array of nav menu objects with new class
|
Deleted: <div id="file- gistfile1-php- LC10"> */</div> | |
Deleted: <div id="file- gistfile1-php- LC11">function tgm_filter_menu_class( $objects ) {</div> | |
Deleted: <div id="file- gistfile1-php- LC12"> </div> | |
| Added: */ |
| Added: function tgm_filter_menu_class( $objects ) { |
Deleted: <div id="file- gistfile1-php- LC13">// Add "first-menu-item" class to the first menu object</div>
| Added: // Add "first-menu-item" class to the first menu object
|
Deleted: <div id="file- gistfile1-php- LC14"> $objects[1]->classes[] = 'first-menu-item'; </div> | |
Deleted: <div id="file- gistfile1-php- LC15"> </div> | |
| Added: $objects[1]->classes[] = 'first-menu-item'; |
Deleted: <div id="file- gistfile1-php- LC16">// Add "last-menu-item" class to the last menu object</div>
| Added: // Add "last-menu-item" class to the last menu object
|
Deleted: <div id="file- gistfile1-php- LC17"> $objects[count( $objects )]->classes[] = 'last-menu-item'; </div>
| Added: $objects[count( $objects )]->classes[] = 'last-menu-item';
|
Deleted: <div id="file- gistfile1-php- LC18"> </div> | |
Deleted: <div id="file- gistfile1-php- LC19">// Return the menu objects</div> | |
Deleted: <div id="file- gistfile1-php- LC20">return $objects;</div> | |
Deleted: <div id="file- gistfile1-php- LC21"> </div> | |
Deleted: <div id="file- gistfile1-php- LC22"> }</div> | |
| Added: // Return the menu objects |
| Added: return $objects; |
| Added: } |
Unchanged: [/php] | Unchanged: [/php] |
No comments yet.