Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter('wp_nav_menu_objects', 'add_menu_parent_class');
- function add_menu_parent_class($items) {
- 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;
- }
- function hasSub($menu_item_id, &$items) {
- foreach ($items as $item) {
- if ($item->menu_item_parent && $item->menu_item_parent==$menu_item_id) {
- return true;
- }
- }
- return false;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement