Opened 12 years ago
Closed 11 years ago
#24101 closed enhancement (wontfix)
Argument for separating wp_nav_menu items
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.6 |
Component: | Menus | Keywords: | has-patch |
Focuses: | Cc: |
Description
There is no proper way to add separators between menu items without generating custom walkers for menus.
The use of menu elements with separators are great for page styling where one doesn't need a menu container like in common primary navigation areas, but rather just want a quick list for example in a page footer.
I feel having to use a custom walker for this purpose is more work then need be, for a feature that would make sense to include with core, the below patch introduces the separator
argument to the mix to address this.
wp_nav_menu( array( 'separator' => ' | ' ) );
The above would output a menu as Menu item | Menu item 2 | Menu item 3
Attachments (1)
Change History (5)
#2
@
12 years ago
That was a terrible place to have a silly typo, my bad on that.
I still feel this is a valid enhancement though, as having to use custom menu walkers for something that you find many sites use is (in my opinion) bad.
The reason why it doesn't add the separator before a menu element is that a separator should come between each one. It was cleaner to use a regex approach, and it shouldn't add any noticeable performance decrease as it will start from the end, and stop after finding a single instance of the separator, but maybe switching it to use a prefixed separator and removing the first instance could be an approach to prevent messing up in case of child menus.
But yes, some added safeguards might not be a bad idea, I don't see someone adding "a" as a separator but suggestions on approaching this are more than welcome so that I can revise the patch and amend it appropriately to suit everyones needs.
#3
follow-up:
↓ 4
@
11 years ago
Would this be better achieved these days with :before/:after content: CSS?
#4
in reply to:
↑ 3
@
11 years ago
- Keywords close removed
- Milestone Awaiting Review deleted
- Resolution set to wontfix
- Status changed from new to closed
Replying to nacin:
Would this be better achieved these days with :before/:after content: CSS?
Yes, or a border and :first-child/:last-child. It's not content.
You can do that already with CSS or a filter on
walker_nav_menu_start_el
.Why is the separator at the end of the item and not at the start?
There is a typo:
esparator
Make sure not to catch the wrong content with the regex:
'separator' => 'a'
would ruin the menu currently.The regex is probably very expensive on large menus. Why didn’t you use a counter and a plain additional string instead?
What happens with nested menus?
I think this is plugin/theme territory. The current walker is complex enough, and most people don’t need more arguments.