Advertisement
Guest User

menu-parent-item class filter

a guest
Aug 6th, 2012
350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.64 KB | None | 0 0
  1. add_filter('wp_nav_menu_objects', 'add_menu_parent_class');
  2.  
  3. function add_menu_parent_class($items) {
  4.    
  5.     foreach ($items as &$item) {
  6.         if (hasSub($item->ID, &$items)) {
  7.             $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
  8.         }
  9.     }
  10.     return $items;    
  11. }
  12.  
  13. function hasSub($menu_item_id, &$items) {
  14.         foreach ($items as $item) {
  15.             if ($item->menu_item_parent && $item->menu_item_parent==$menu_item_id) {
  16.                 return true;
  17.             }
  18.         }
  19.         return false;
  20. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement