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'; } } } } return $sorted_menu_items; } add_filter( 'wp_nav_menu_objects', 'charity_review_bootstrap_menu_objects', 10, 2 ); /** * Custom Bootstrap Walker */ class charity_review_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); $submenu = ( $depth > 0 ) ? ' sub-menu' : ''; $output .= "\n$indent