Adding first / last CSS classes to menus

A better and simpler approach:

function add_first_and_last($items) {
  $items[1]->classes[] = 'first-menu-item';
  $items[count($items)]->classes[] = 'last-menu-item';
  return $items;
}

add_filter('wp_nav_menu_objects', 'add_first_and_last');

Leave a Comment

techhipbettruvabetnorabahisbahis forumutaraftarium24eduedusedusedueduedueduseduedusedus