Created
October 31, 2012 09:00
-
-
Save ciorici/3985965 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter('wp_nav_menu_objects', function ($items) { | |
$hasSub = function ($menu_item_id, &$items) { | |
foreach ($items as $item) { | |
if ($item->menu_item_parent && $item->menu_item_parent==$menu_item_id) { | |
return true; | |
} | |
} | |
return false; | |
}; | |
foreach ($items as &$item) { | |
if ($hasSub($item->ID, &$items)) { | |
$item->classes[] = 'menu-parent-item'; // all elements of field "classes" of a menu item get join together and render to class attribute of <li> element in HTML | |
} | |
} | |
return $items; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment