[wp-hackers] wp_nav_menu too simplistic?
Mike Schinkel
mikeschinkel at newclarity.net
Tue Apr 6 21:02:17 UTC 2010
On Apr 6, 2010, at 4:24 PM, Otto wrote:
> On Tue, Apr 6, 2010 at 3:17 PM, Otto <otto at ottodestruct.com> wrote:
>> On Tue, Apr 6, 2010 at 3:13 PM, John Bloch <jbloch at olympianetworks.com> wrote:
>>> This custom walker class will give you a filter to directly modify the
>>> url of individual menu items. Put this into your theme's function file
>>> and, when you call the menu, add "walker=Custom_Walker_Nav_Menu" to
>>> the function's arguments.
>>
>> So what you're saying is that you can't make a plugin do it, it has to
>> be a theme that does it, by modifying the call to wp_nav_menu.
>
> Ahh, no, a plugin can do it. There's a filter you can use to force the
> walker, "wp_nav_menu_args".
As far as I can tell that hook is on a menu-wide basis not on a menu item basis, right?
On a related note I recently tried to add a css class to a menu item and couldn't figure it out because there didn't appear to be any hooks for annotating/modifying menu items. (More on this in the P.S.)
> BTW, in your example, it would actually make more sense for
> Custom_Walker_Nav_Menu to extend Walker_Nav_Menu. Then you could
> override just the start_el function, leaving the rest alone.
For the case of modifying menu items it seems it would solve some use cases if we simply added a 'wp_setup_nav_menu_item' filter on the return value of the wp_setup_nav_menu_item() function. If others agree, I can submit a patch...
-Mike
P.S. In order to test this theory before sending this email I traced some code and found, lo-and-behold, there is the hook I needed. It's buried deep in the Walker class that I previously decided was more complex than I wanted to trace through. So for anyone finding this thread by googling for something like "wordpress css class menu item", the way to add a CSS class for a menu item use the (appropriately named) "nav_menu_css_class" hook.
More information about the wp-hackers
mailing list