3

I'm creating a website for my school with Material Design for Bootstrap and the NavWalker is giving me some issues, I want to change the element of dropdown i.e. from ul to div. I've tried to edit the NavWalker.

$output .= "\n$indent<div class=\" dropdown-menu dropdown-primary\" aria-labelledby=\"navbarDropdownMenuLink\" >\n";

I've edited the code and replaced the DIV instead of UL but don't know how to close the DIV. When I opened the Source Code it display like this

<div class=" dropdown-menu dropdown-promary" aria-labelledby="navbarDropdownMenuLin*k" >
    <li  class="menu-item menu-item-type-post_type menu-item-object-page menu-item-60"><a title="About Us" href="http://example.com/about/">About Us</a></li>
    <li  class="menu-item menu-item-type-custom menu-item-object-custom menu-item-63"><a title="Year Plan" href="http://example.com/year-plan/">Year Plan</a></li>
    <li  class="menu-item menu-item-type-custom menu-item-object-custom menu-item-64"><a title="Staff" href="http://example.com/staff/">Staff</a></li>
    <li  class="menu-item menu-item-type-custom menu-item-object-custom menu-item-65"><a title="Fee and Uniform" href="http://example.com/fee-and-uniform">Fee and Uniform</a></li>
</ul>

This spoiled my navbar! Please help if anyone knows how to solve this issue. These are the links to NavWalker and the one that I've edited.

The original NavWalker file in text file Original NavWalker

The original NavWalker file in text file The Modified One

1 Answer 1

0

You need to replace the end_lvl method of Walker_Nav_Menu as well. This is what you would need to add:

public function end_lvl( &$output, $depth = 0, $args = array() ) {
    if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) {
        $t = '';
        $n = '';
    } else {
        $t = "\t";
        $n = "\n";
    }
    $indent = str_repeat( $t, $depth );
    $output .= "$indent</div>{$n}";
}

The only change from the original is the </ul> was changed to </div>

1
  • Jacob, do you have any recommended sources online on how we can expose anchor links instead of li elements, since this user wanted to use a div element instead of a unordered list parent? I feel stuck on how to change elements for sub menus with the nav walker.
    – klewis
    Commented Jan 10, 2019 at 16:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.