Ticket #16738 (new enhancement)

Opened 15 months ago

Last modified 15 months ago

Add filter for attributes on menu item links

Reported by: simonwheatley Owned by:
Priority: normal Milestone: Awaiting Review
Component: Menus Version:
Severity: normal Keywords: dev-feedback has-patch
Cc:

Description

I find myself needing to change the attributes of the link element of each menu item to add some classes. Currently I can do this by extending and substituting Walker_Nav_Menu, but that the start_el method I replace is fairly long and I'm nervous of changes to core breaking my kit in the future. Much better to be able to hook a filter, IMO.

Attachments

add nav_menu_a_attributes filter.patch Download (1.5 KB) - added by simonwheatley 15 months ago.
I propose a new nav_menu_a_attributes filter in the start_el method of Walker_Nav_Menu, as per the attached patch.

Change History

I propose a new nav_menu_a_attributes filter in the start_el method of Walker_Nav_Menu, as per the attached patch.

  • Keywords has-patch added

In the patch I've also changed the way the attributes are built up within start_el so they work with a named array, as it is easier for plugin authors to then parse the attributes as an array than if they are passed a long string of HTML attributes. Hope that makes sense.

Looks good to me.

Note: See TracTickets for help on using tickets.