Skip to content

Instantly share code, notes, and snippets.

@ciorici
Created October 31, 2012 09:00
Show Gist options
  • Save ciorici/3985965 to your computer and use it in GitHub Desktop.
Save ciorici/3985965 to your computer and use it in GitHub Desktop.
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