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
May 2018 this solution worked for me.
Go to your class-wp-bootstrap-navwalker.php file -> comment line 185
// $atts['href'] = '#';
And paste this code.
$atts['href'] = ! empty( $item->url ) ? $item->url : '';
$atts['data-toggle'] = 'hover';
Enjoy.
You can set that by removing data-toggle="dropdown" and setting data-hover="dropdown".
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!
Easy to use below code for clickable link in drapdown
onClick="parent.location='http://www.plus2net.com/'"
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.
By default bootstrap parent items on a dropdown are not clickable. Add this script to your page and now they will be:
<script>
jQuery(function($) {
$('.navbar .dropdown').hover(function() {
$(this).find('.dropdown-menu').first().stop(true, true).delay(250).slideDown();
}, function() {
$(this).find('.dropdown-menu').first().stop(true, true).delay(100).slideUp();
});
$('.navbar .dropdown > a').click(function(){
location.href = this.href;
});
});
</script>
Credit for this solution goes to http://wpeden.com/tipsntuts/twitter-bootstrap-dropdown-on-hover-and-activating-click-event-on-parent-item/