WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 4 years ago

Last modified 12 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:

Description

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.

Example:
Start | About | Contact

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

Example:
.menu-item-first .menu-item-last

Change History (7)

comment:2 @hakre5 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:
http://www.w3.org/TR/CSS2/selector.html

even, odd and nth child:
http://www.w3.org/Style/Examples/007/evenodd

CSS3 pseudo classes:
http://www.w3.org/TR/css3-selectors/#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.

comment:3 @trilibi5 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.

comment:4 @fjarrett4 years ago

@trilibi - excellent! thank you very much :)

comment:5 @nacin4 years ago

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

comment:6 @hm2k4 years ago

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

comment:7 @helen12 months ago

#27616 was marked as a duplicate.

Note: See TracTickets for help on using tickets.