questions

Remove Active Class from Parent when Child is Active in WP SubMenu

Rate this post
<ul class="list-group">
  <li>
    <a href="#" class="list-group-item list-group-item-action active">
      Cras justo odio
    </a>

    <ul>
      <li>
        <a href="#" class="list-group-item list-group-item-action ">Dapibus ac facilisis in
        </a>
      </li>
      <li>
        <a href="#" class="list-group-item list-group-item-action active">Dapibus ac facilisis in
        </a>
      </li>

    </ul>

  </li>
  <li>
    <a href="#" class="list-group-item list-group-item-action">Dapibus ac facilisis in
    </a>
  </li>
</ul>

I have a menu with secondary items in WordPress. It works great except the active class should only be on the child when that page is active. Right now it is active on both. What is the best way to remove it? jQuery, Filter, or Editing the Walker. This is Bootstrap based theme so it is using the bootstrap nav walker from GitHub (wp-bootstrap/wp-bootstrap-navwalker)

 

✔️Solution:

Change

if ( in_array( 'current-menu-item', $classes, true ) || in_array( 'current-menu-parent', $classes, true ) ) {
                    $classes[] = 'active';
                }

to

if ( in_array( 'current-menu-item', $classes, true ) ) {
                $classes[] = 'active';
            }

In the bootstrap nav walker

Leave a Reply

Your email address will not be published.

Back to top button