#16738 closed enhancement (fixed)
Add filter for attributes on menu item links
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | 3.6 |
| Component: | Menus | Version: | |
| Severity: | normal | Keywords: | has-patch commit needs-codex |
| Cc: | xoodrew@… |
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)
comment:1
simonwheatley — 2 years ago
- Keywords has-patch added
comment:2
simonwheatley — 2 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.
comment:4
DrewAPicture — 3 months 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.
comment:5
SergeyBiryukov — 3 months ago
- Milestone changed from Awaiting Review to 3.6
comment:6
SergeyBiryukov — 3 months ago
Perhaps nav_menu_link_attributes is a better name, for consistency with *_posts_link_attributes and *_comments_link_attributes.
DrewAPicture — 3 months ago
comment:7
DrewAPicture — 3 months ago
Replying to SergeyBiryukov:
Perhaps nav_menu_link_attributes is a better name, for consistency with *_posts_link_attributes and *_comments_link_attributes.
+1 for consistency in naming :) Updated the patch.
SergeyBiryukov — 3 months ago
comment:8
SergeyBiryukov — 3 months 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.
comment:9
DrewAPicture — 3 months ago
16738.3.diff works for me.
comment:10
SergeyBiryukov — 3 months ago
- Keywords commit added; dev-feedback removed
comment:11
SergeyBiryukov — 3 months ago
- Owner set to SergeyBiryukov
- Resolution set to fixed
- Status changed from new to closed
In 23565:
comment:12
DrewAPicture — 3 months ago
- Keywords 3.6-codex added
comment:13
DrewAPicture — 3 months ago
- Keywords needs-codex added; 3.6-codex removed
