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.
3 Answers
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 :has()
selector:
$('#nav-id').find('li:has(ul)').addClass('parent');