#16738 closed enhancement (fixed)
Add filter for attributes on menu item links
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 3.6 | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | Menus | Keywords: | has-patch commit needs-codex |
| Focuses: | 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 (4)
Change History (17)
#2
@
15 years ago
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.
#4
@
13 years ago
- Cc xoodrew@… added
I like this. Would be nice to get this in.
16738.diff refreshes @simonwheatley's patch and makes an effort to keep the format more succinct like it was originally.
#6
@
13 years ago
Perhaps nav_menu_link_attributes is a better name, for consistency with *_posts_link_attributes and *_comments_link_attributes.
#7
@
13 years ago
Replying to SergeyBiryukov:
Perhaps
nav_menu_link_attributesis a better name, for consistency with*_posts_link_attributesand*_comments_link_attributes.
+1 for consistency in naming :) Updated the patch.
#8
@
13 years ago
If a plugin adds $atts['class'] = 'class="my-menu-link"', adding a second class may be a non-trivial task.
I guess it would be easier to modify the attributes if the array values were the actual attribute values rather than key-value pairs: 16738.3.diff.