Is there a good way to add a class of "parent" to list items that have children using wp_nav_menu?
I've found a couple of solutions online but non seem to have the desired effect.
|
Is there a good way to add a class of "parent" to list items that have children using wp_nav_menu? I've found a couple of solutions online but non seem to have the desired effect. |
|||
|
|
|
This may not be the ideal solution, depending on what you need the class for, but you could add a "parent" class via JavaScript. The line below uses the jQuery
|
|||
|
|
|
See Wordpress codex http://codex.wordpress.org/Function_Reference/wp_nav_menu#How_to_add_a_parent_class_for_menu_item Use this function:
|
|||
|
|
|
You can do it with a bit of regex and a custom menu walker although I've not tested this thoroughly:
What this does is every time we start a new level within the menu we look at the last opening To use the above just pass in the walker argument where you declare your menu eg:
|
|||
|
|