Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

this is my custom walker function.

class Bootstrap_Walker extends Walker_Nav_Menu
{    
function start_lvl(&$output, $depth = 0, $args = array()) {
  $output .= "\n<ul class=\"dropdown-menu\">\n";
 }


function start_el(&$output, $item, $depth, $args) {
   $item_html = '';
   parent::start_el($item_html, $item, $depth, $args);


   if ( $item->is_dropdown && $depth === 0 ) {

       $item_html = str_replace( '<a', '<a class="dropdown-toggle " data-toggle="dropdown"', $item_html );
       $item_html = str_replace( '</a>', ' <b class="caret"></b></a>', $item_html );
   }

   $output .= $item_html;
}

function display_element($element, &$children_elements, $max_depth, $depth, $args, &$output) {
    if ( $element->current )
    $element->classes[] = 'active';

   $element->is_dropdown = !empty( $children_elements[$element->ID] );
//$element->hasChildren = isset($children_elements[$element->ID]) && !empty($children_elements[$element->ID]);
   if ( $element->is_dropdown ) {
        if ( $element->has_children) {
            $element->classes[] = 'open';
        } else{

            $element->classes[] = 'dropdown';
        }
    }

  return parent::display_element($element, $children_elements, $max_depth, $depth, $args, $output);
    }  

}

the "open" class is used for showing the submenu. please help me to find the errors.

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.