I have recently started learning how to use WordPress, and I have selected a simple theme and want to implement the bootstrap navbar fixed-top menu.
I have so far succeed, and have the menu working when the screen is in full mode, and loads in the correct primary menu.
However, I need help with a couple things.
- Firstly, I have the navbar set so when you hover over a Dropdown, it auto dropdowns the sub menu, but I would like the parent link to be clickable to it’s relevant page also
- In standard
HTML
&CSS
, this is simple to do, but in WordPress, when you load in the menu I find it a bit more complex.
Here is how I have input the navbar within the header.php
file:
<div class="navbar navbar-inverse navbar-fixed-top">
<?php
// Fix menu overlap bug..
if ( is_admin_bar_showing() ) echo '<div style="min-height: 28px;"></div>';
?>
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/"><?php echo esc_attr( get_bloginfo( 'name' ) ); ?></a>
</div>
<?php
wp_nav_menu( array(
'menu' => 'primary-menu',
'theme_location' => 'primary-menu',
'depth' => 2,
'container' => 'div',
'container_class' => 'navbar-collapse collapse',
'container_id' => 'bs-example-navbar-collapse-1',
'menu_class' => 'nav navbar-nav',
'fallback_cb' => 'wp_bootstrap_navwalker::fallback',
'walker' => new wp_bootstrap_navwalker())
);
?>
</div>
</div>
As you can see that the primary menu is loaded in with some PHP. The issue with this is, it does not allow for me to change the a class=""
on a Link so I can input disable
, so it can be clicked as a Link.
Also the Link is currently ‘#’ which I cannot change.
Lastly, when I resize my browser to check if the menu is responsive, when the toggle button displays, I click that and it shows the links, once I hover over the link with a sub menu it again auto drops down (which is not what I want when the responsive toggle menu is displayed). I want to click the link when the menu is shrunk down, rather than auto dropdown on full view.
If you want to make the Parent Link clickable you need to edit the
wp_bootstrap_navwalker.php
.I have done this before by editing some lines within the
wp_bootstrap_navwalker.php
file and here’s how.First fine this line of code:
These lines of code are normally around
line 78
toline 91
what you can do is replace all of the lines above with these lines of code:What I have done here is I have changed the parent link to print its own link instead of replacing it with a
#
Instead of the original which was to change the parent link to a
#