Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to change navwalker's dropdown mark-up? #390

Open
robertandrews opened this issue Jul 18, 2018 · 2 comments
Open

How to change navwalker's dropdown mark-up? #390

robertandrews opened this issue Jul 18, 2018 · 2 comments
Assignees

Comments

@robertandrews
Copy link

robertandrews commented Jul 18, 2018

I am using Bootstrap 4 Navwalker to step through my WordPress menu items and generate a navbar, like...

Single level - works

    <?php
    wp_nav_menu([
      'menu'            => 'primary',
      'theme_location'  => 'primary',
      'container'       => 'nav',
      'container_class' => 'sidebar-nav',
      'menu_id'         => 'sidebarnav',
      'depth'           => 2,
  'fallback_cb'     => 'WP_Bootstrap_Navwalker::fallback',
  'walker'          => new WP_Bootstrap_Navwalker(),
    ]);
    ?>

This correctly generates a navbar like ...

enter image description here

<nav class="sidebar-nav">
    <ul id="sidebarnav" class="menu">
        <li id="menu-item-3" class="menu-item menu-item-type-custom menu-item-object-custom current-menu-item current_page_item menu-item-home menu-item-3 nav-item active">
            <a title="Home Page" target="_blank" href="/" class="nav-link active" aria-expanded="false">
                <i class="icon-speedometer"></i>Home Page
            </a>
        </li>
        <li id="menu-item-4" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-4 nav-item">
            <a title="Example Page" target="_blank" href="http://example.com/" class="nav-link" aria-expanded="false">
                <i class="ti-layout-grid2"></i>Example Page
            </a>
        </li>
        <li id="menu-item-5" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-5 nav-item">
            <a title="Custom Page" target="_blank" href="http://example.com/custom/" class="nav-link" aria-expanded="false">
                <i class="ti-palette"></i>Custom Page
            </a>
        </li>
    </ul>
</nav>

Multi-level - preferred

The problem happens when it comes to drop-down/sub-menu items...

My theme handles those like this...

enter image description here

<nav class="sidebar-nav">
  <ul id="sidebarnav">
      <li class="selected">
            <a class="has-arrow waves-effect waves-dark" href="javascript:void(0)" aria-expanded="false">
                <i class="icon-speedometer"></i>
                <span class="hide-menu">
                    Dashboard <span class="badge badge-pill badge-cyan">4</span>
                </span>
            </a>
            <ul aria-expanded="false" class="collapse">
              <li><a href="index.html">Minimal</a></li>
              <li><a href="index2.html">Analytical</a></li>
              <li><a href="index3.html">Demographical</a></li>
              <li class="active"><a href="index4.html" class="active">Modern</a></li>
              <li><a href="index5.html">Cryptocurrency</a></li>
          </ul>
      </li>
      <li>
          <a class="has-arrow waves-effect waves-dark" href="javascript:void(0)" aria-expanded="false">
                <i class="ti-layout-grid2"></i>
                <span class="hide-menu">Apps</span>
          </a>
          <ul aria-expanded="false" class="collapse">
              <li><a href="app-calendar.html">Calendar</a></li>
              <li><a href="app-chat.html">Chat app</a></li>
              <li><a href="app-ticket.html">Support Ticket</a></li>
              <li><a href="app-contact.html">Contact / Employee</a></li>
              <li><a href="app-contact2.html">Contact Grid</a></li>
              <li><a href="app-contact-detail.html">Contact Detail</a></li>
              <li><a href="javascript:void(0)" class="has-arrow">Inbox</a>
                  <ul aria-expanded="false" class="collapse">
                      <li><a href="app-email.html">Mailbox</a></li>
                      <li><a href="app-email-detail.html">Mailbox Detail</a></li>
                      <li><a href="app-compose.html">Compose Mail</a></li>
                  </ul>
              </li>
          </ul>
      </li>
    </nav>

... That is, it:

  • adds a <span> with .hide-menu inside the top-level link <a>
  • adds an <ul> unordered list afterward.

This is the approach I want to stick to.

Multi-level: what navwalker gives

However, when using the navwalker, I get...

enter image description here

<nav class="sidebar-nav">
    <ul id="sidebarnav" class="menu">
        <li id="menu-item-3" class="menu-item menu-item-type-custom menu-item-object-custom current-menu-item current_page_item menu-item-home menu-item-has-children menu-item-3 nav-item dropdown active">
            <a title="Home Page" target="_blank" href="/" class="nav-link dropdown-toggle active" data-toggle="dropdown" aria-expanded="false">
                <i class="icon-speedometer"></i>Home Page</a>
                <div class="dropdown-menu">
                    <a href="/sample-page/" class="dropdown-item" aria-expanded="false"><i class="ti-palette"></i>Sample Page</a>
                </div>
        </li>
        ...
    </ul>
</nav>

That is, it...

  • places a <div> with .dropdown-menu inside the <a>, instead of a <span> with .hide-menu
  • for the sub-menu items, uses <a> elements

I'm sure this is standard Bootstrap 4 behaviour - in fact, I have happily used it this way on a different site. However, it's not what is needed by the Bootstrap 4 theme which I have purchased and am currently trying to turn in to a WordPress theme...

The question

How can I use the navwalker but in a way that will present drop-down/sub-menu items in a manner consistent with my theme... ?

@pattonwebz
Copy link
Member

Hey @robertandrews,

I know it's been a very long time since you posted this and I am sorry for not getting around to responding. In it's current state the navwalker doesn't handle the situation you need very well (at all really) but I have been looking into adding filters/toggles for changing the markup here and plan to work on the updated walker very soon.

I realise this has come around much too late for your needs but I am going to work on something similar to this in the coming weeks and may use this issue to track some progress.

Thanks for opening this issue and I do hope you were able to get a solution for it back at the time.

@robertandrews
Copy link
Author

Hi @pattonwebz - thanks for the reply :-)
I did not go ahead with implementing that specific theme and am currently building my own, which is essentially nothing much on top of Bootstrap 4.
I can't recall the specifics of my post, so not sure whether this was edge case for you anyway or something that would have been a useful inclusion.

Currently running https://github.com/dupkey/bs4navwalker during the build - maybe I should give this one a try, too.
Thanks for responding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants