Bootstrap: How do I make Dropdown navigation Parent links an active link?

前端 未结 7 744
我在风中等你
我在风中等你 2021-01-30 07:50

I am running Bootstrap on a WP install and have an issue with the url being stripped from the parent drop down nav item.

Here is the code. In menu-item-72

7条回答
  •  逝去的感伤
    2021-01-30 08:26

    For me it worked this way: I assume you make usage of the wp-bootstrap-navwalker

    Open up the wp-bootstrap-navwalker.php with your editor and look up for line approx.

    // If item has_children add atts to a.
    if ( $args->has_children && $depth === 0 ) {
       $atts['href']        = '#';
       $atts['data-toggle'] = 'dropdown';
       $atts['class']           = 'dropdown-toggle';
    } else {
       $atts['href'] = ! empty( $item->url ) ? $item->url : '';
    }
    

    Change this piece of code to:

    // If item has_children add atts to a.
    if ( $args->has_children && $depth === 0 ) {
       $atts['href'] = ! empty( $item->url ) ? $item->url : '';
       //$atts['data-toggle']   = 'dropdown';
       $atts['class']           = 'dropdown-toggle';
    } else {
       $atts['href'] = ! empty( $item->url ) ? $item->url : '';
    }
    

    Note: $att['href'] is enabled now, the the $atts['data-toggle'] is disabled which makes the parent link clickable.

    Now open up your style.css and add this piece of code to activate the hover function for your WordPress menu with dropdown and clickable parent.

    .dropdown:hover .dropdown-menu {
        display: block;
    }

    Note: The behaviour of the menu will change slightly on small devices with small screens. No additional jQuery required.

提交回复
热议问题