Revisions
- April 12, 2013 @ 00:04:31 [Current Revision] by PeterLugg
- April 12, 2013 @ 00:09:36 [Autosave] by PeterLugg
- April 11, 2013 @ 23:58:01 by PeterLugg
- April 11, 2013 @ 23:54:09 by PeterLugg
Revision Differences
April 11, 2013 @ 23:58:01 | Current Revision | ||
---|---|---|---|
Content | |||
Added: <a href="https:/ /gist.github.com/ thomasgriffin/4253190" target="_blank" >https://gist.github.com/ thomasgriffin/4253190</a> | |||
Deleted: <p><a href="https:/ /gist.github.com/ thomasgriffin/4253190" target="_blank" >https://gist.github.com/ thomasgriffin/4253190</a> </p><p>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.</p> <p>[php]</ p><div id="file- gistfile1-php- LC1">add_filter( 'wp_nav_menu_objects', 'tgm_filter_menu_class' );</div><div id="file- gistfile1-php- LC2"> /**</div><div id="file- gistfile1-php- LC3">* Filters the first and last nav menu objects in your menus</div><div id="file- gistfile1-php- LC4">* to add custom classes.</ div><div id="file- gistfile1-php- LC5"> *</div><div id="file- gistfile1-php- LC6">* @since 1.0.0</div><div id="file- gistfile1-php- LC7"> *</div><div id="file- gistfile1-php- LC8">* @param object $objects An array of nav menu objects</div><div id="file- gistfile1-php- LC9">* @return object $objects Amended array of nav menu objects with new class</div><div id="file- gistfile1-php- LC10"> */</div><div id="file- gistfile1-php- LC11">function tgm_filter_menu_class( $objects ) {</div><div id="file- gistfile1-php- LC12"> </div><div id="file- gistfile1-php- LC13">// Add "first-menu-item" class to the first menu object</div><div id="file- gistfile1-php- LC14"> $objects[1]-& gt;classes[] = 'first-menu-item'; </div><div id="file- gistfile1-php- LC15"> </div><div id="file- gistfile1-php- LC16">// Add "last-menu-item" class to the last menu object</div><div id="file- gistfile1-php- LC17"> $objects[count( $objects )]-&gt;classes[] = 'last-menu-item'; </div><div id="file- gistfile1-php- LC18"> </div><div id="file- gistfile1-php- LC19">// Return the menu objects</div><div id="file- gistfile1-php- LC20">return $objects;< /div><div id="file- gistfile1-php- LC21"> </div><div id="file- gistfile1-php- LC22"> }</div> <p>[/php]<br /><br /></p> | 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. | ||
Added: [php] | |||
Added: add_filter( 'wp_nav_menu_objects', 'tgm_filter_menu_class' ); | |||
Added: /** | |||
Added: * Filters the first and last nav menu objects in your menus | |||
Added: * to add custom classes. | |||
Added: * | |||
Added: * @since 1.0.0 | |||
Added: * | |||
Added: * @param object $objects An array of nav menu objects | |||
Added: * @return object $objects Amended array of nav menu objects with new class | |||
Added: */ | |||
Added: function tgm_filter_menu_class( $objects ) { | |||
Added: // Add "first-menu-item" class to the first menu object | |||
Added: $objects[1]->classes[] = 'first-menu-item'; | |||
Added: // Add "last-menu-item" class to the last menu object | |||
Added: $objects[count( $objects )]->classes[] = 'last-menu-item'; | |||
Added: // Return the menu objects | |||
Added: return $objects; | |||
Added: } | |||
Added: [/php] |
Note: Spaces may be added to comparison text to allow better line wrapping.
No comments yet.