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

前端 未结 7 838
我在风中等你
我在风中等你 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:22

    To add on to Sohail Qureshi's solution, I modified the file a bit more, and here's a way that converts the parent link to an actual link:

    in wp-bootstrap-navwalker.php, change this piece of code:

    // 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 : '';
    }
    

    to:

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

    and now the parent link is clickable and actually link to page!

提交回复
热议问题