Make WordPress Core

Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#14040 closed enhancement (invalid)

Prevent empty class attribute in start_el of the Walker_Nav_Menu walker class

Reported by: jaapjanfrans's profile jaapjanfrans Owned by:
Milestone: Priority: normal
Severity: minor Version: 3.0
Component: Themes Keywords: walker, start_el, class attribute
Focuses: Cc:

Description

If you filter the classes of a menu item by adding a filter to the hook 'nav_menu_css_class' and your filter function returns an empty array then a 'class=' string is still added to the output of the element.

I would like the function to check if the $classes string is empty or not and decide to add 'class=' + $classes only if $classes is not empty.

Current code:

$classes = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
		$classes = ' class="' . esc_attr( $classes ) . '"';

possible solution:

$classes = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
		if(!empty($classes))
		{
			$classes = ' class="' . esc_attr( $classes ) . '"';
		}
		else
		{
			$classes = '';
		}

Change History (2)

#1 @jaapjanfrans
14 years ago

  • Resolution set to invalid
  • Status changed from new to closed

#2 @scribu
14 years ago

  • Milestone Unassigned deleted
Note: See TracTickets for help on using tickets.