theme_location == 'primary') {// $current = array('current-menu-ancestor', 'current-menu-item'); $registry = array(); foreach($sorted_menu_items as $i => $item) { $is_current = array_intersect( (array) $item->classes, $current ); if ( !empty($is_current) ) $item->classes[] = 'active'; $registry[$item->ID] = $i; if($item->menu_item_parent) { $parent_index = $registry[$item->menu_item_parent]; if( !in_array('dropdown', $sorted_menu_items[$parent_index]->classes) ) { $sorted_menu_items[$parent_index]->classes[] = 'dropdown'; } } } //print_r($sorted_menu_items);print_r($args);exit; } return $sorted_menu_items; } add_filter( 'wp_nav_menu_objects', 'bootstrap_menu_objects', 10, 2 ); /** * Custom Bootstrap Walker */ class Bootstrap_Nav_Menu extends Walker_Nav_Menu { /** * @see Walker::start_lvl() * @since 3.0.0 * * @param string $output Passed by reference. Used to append additional content. * @param int $depth Depth of page. Used for padding. */ function start_lvl( &$output, $depth = 0, $args = array() ) { $indent = str_repeat("\t", $depth); $output .= "\n$indent