Revision: 32577
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at September 29, 2010 07:21 by fjarrett
Initial Code
// Assign Unique Classes To First And Last Menu Items function first_last_class( $items ) { $position = strrpos($items, 'class="menu-item', -1); $items=substr_replace($items, 'menu-item-last ', $position+7, 0); $position = strpos($items, 'class="menu-item'); $items=substr_replace($items, 'menu-item-first ', $position+7, 0); return $items; } add_filter( 'wp_nav_menu_items', 'first_last_class' );
Initial URL
Initial Description
Use this function to filter your first and last menu items and assign them each a specific class name. This is very handy when applying separators in CSS but want to exclude the first and/or last items.
Initial Title
Assign Unique Classes To First And Last Menu Items
Initial Tags
wordpress
Initial Language
PHP