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.

i'm trying to develop a responsive theme in wordpress with twitter Bootstrap v3.0.2. and in order to integrate bootstrap menu with my theme i use the below code in my function.php

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);
    }  

}

my problem: this code creates an arrow near to the parent menu item. but when i clicked on that the drop down list is not displaying.

output code

<li id="menu-item-17" class="menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-10 current_page_item active dropdown menu-item-17">
<a class="dropdown-toggle " data-toggle="dropdown" href="http://mysite">Lorem Ipsum 
<b class="caret"></b>
 </a>
<ul class="dropdown-menu">
<li id="menu-item-86" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-86"><a href="mysite/test/">test</a></li>
</ul>
</li>

I would really appreciate a solution to this problem..

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.