WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 2 years ago

#20483 closed enhancement (fixed)

Do not output nav menu class attribute if no classes exist

Reported by: niallkennedy Owned by: nacin
Milestone: 3.4 Priority: normal
Severity: trivial Version:
Component: Menus Keywords: has-patch
Focuses: Cc:

Description

Walker_Nav_Menu->start_el passes an array of class names and a string through class and id filters respectively. It's possible for a theme or plugin to empty out a class or id, overriding defaults.

The element string builder checks for an empty id attribute string value before outputting the id attribute. If a plugin empties the classes array then $classes_name will be similarly empty.

Patch applies the same conditional attribute output logic present in the id attribute to the class attribute as well.

Attachments (1)

nav-menu-template.diff (695 bytes) - added by niallkennedy 2 years ago.
check if classes_name is an empty string before building an empty attribute for a nav menu walker element

Download all attachments as: .zip

Change History (3)

niallkennedy2 years ago

check if classes_name is an empty string before building an empty attribute for a nav menu walker element

comment:1 nacin2 years ago

  • Milestone changed from Awaiting Review to 3.4

Looks good. A note, strlen() is not necessary in either place.

comment:2 nacin2 years ago

  • Owner set to nacin
  • Resolution set to fixed
  • Status changed from new to closed

In [20513]:

Only output the class attribute in wp_nav_menu() if we have classes to add. Don't waste time on an strlen() call. props niallkennedy, fixes #20483.

Note: See TracTickets for help on using tickets.