Make parent link clickable in Bootstrap with Wordpress NavWalker

Scenario:

You are developing a Wordpress site and you are using Bootstrap, I for one use wp-bootstrap-navwalker by Edward McIntyre to take away the heavy lifting when building menus. If, like many of us, you are required for some special reason (life or death) to make the parent link of a drop-down click through to a url instead of revealing the drop-down menu under it — I have found the solution/hack :-).

Assumptions:

  • You are developing a Wordpress theme
  • You are using the wp-bootstrap-navwalker

You only have to change 2 lines of code in the wp_bootstrap_navwalker.php file.

Before

On line 85:
$atts['href'] = '#';
On line 87:
$atts['data-toggle'] = 'dropdown';

After

On line 85:
$atts['href'] = ! empty( $item->url ) ? $item->url : '';
On line 87:
$atts['data-hover'] = 'dropdown';

Voila.