Make WordPress Core

Opened 5 years ago

Closed 5 years ago

Last modified 20 months ago

#14250 closed feature request (wontfix)

wp_nav_menu separator and first last class

Reported by: spathon Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: General Keywords: wp_nav_menu
Focuses: Cc:


In some of the wp sites I do there is a separator between the menu items and I think it would be good if there were some argument to add separators to the wp_nav_menu($args).
Like now you can use link_before or link_after but you don't want the last or first to have it.

Start | About | Contact

And it would be good if there were a first and last class on the items

.menu-item-first .menu-item-last

Change History (7)

#2 @hakre
5 years ago

I think adding "first" and "last" is enough when it's added additionally. I've implemented something like that for widgets: #12615

I do not see any first and last selectors in css2:

even, odd and nth child:

CSS3 pseudo classes:

I have no idea which browser do really support that, so it might just be useful to have some classes for older browsers.

#3 @trilibi
5 years ago

Here is a little filter I use to help with first and last.

function nav_menu_first_last( $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', 'nav_menu_first_last' );

@hakre - You are correct on the lack of support for the first/last pseudo selectors. Probably less then half of the browsers out there support it.

#4 @fjarrett
5 years ago

@trilibi - excellent! thank you very much :)

#5 @nacin
5 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

#6 @hm2k
4 years ago

adding first/last classes is a duplicate of #9011.

#7 @helen
20 months ago

#27616 was marked as a duplicate.

Note: See TracTickets for help on using tickets.