Comments (14)
I've been banging my head over this for a couple days now and I FINALLY got it to work. The problem is with how codepen loads its scripts. i had bootstrap loaded under css and jquery under JS - but you also have to go into JS and have it load bootstrap ALSO - after jquery. suddenly all the dropdowns worked
from wp-bootstrap-navwalker.
I'm not having any problems with this and 3.0.3. Sounds like an implementation problem. Have you checked your dev tools console for errors?
from wp-bootstrap-navwalker.
I do agree with @mindctrl in this one, everything it working great for me in multiple themes I have running 3.0.3 so at this point I would say its an implementation issue, but I will definitely try to help you out.
Lets troubleshoot the walker first, can you please share your wp_nav_menu()
declaration and the outputted HTML so we can confirm if there are any issues with the walker itself? Then we can move forward with looking at JS issues.
from wp-bootstrap-navwalker.
//header.php
<div class="navbar navbar-default navbar-static-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
<span class="sr-only">Navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<?php
wp_nav_menu( array(
'menu' => 'primary',
'theme_location' => 'primary',
'depth' => 2,
'container' => 'div',
'container_class' => 'collapse navbar-collapse navbar-ex1-collapse',
'menu_class' => 'nav navbar-nav',
'fallback_cb' => 'wp_bootstrap_navwalker::fallback',
'walker' => new wp_bootstrap_navwalker())
);
?>
</ul>
</div>
</div>
</div>
//functions.php:
// Register Custom Navigation Walker
require_once('wp_bootstrap_navwalker.php');
// Register navigation menu
register_nav_menus( array(
'primary' => __( 'Primary Menu', 'MYTHEME' ),
) );
from wp-bootstrap-navwalker.
Everything looks good here, as mentioned I will also need to take a look at the outputted menu HTML that is rendered when the page loads.
from wp-bootstrap-navwalker.
<div class="navbar navbar-default navbar-static-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
<span class="sr-only">Navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul id="menu-headermenu" class="nav navbar-nav"><li id="menu-item-152" class="menu-item menu-item-type-custom menu-item-object-custom current-menu-item menu-item-home menu-item-152 active"><a title="Home" href="http://mysite.com">Home</a></li>
<li id="menu-item-46" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children menu-item-46 dropdown"><a title="About" href="#" data-toggle="dropdown" class="dropdown-toggle">About <span class="caret"></span></a>
<ul role="menu" class=" dropdown-menu">
<li id="menu-item-70" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-70"><a title="History" href="http://mysite.com/history/">History</a></li>
<li id="menu-item-59" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-59"><a title="Services" href="http://mysite.com/services/">Services</a></li>
</ul></li>
<li id="menu-item-64" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-64"><a title="Classes" href="http://mysite.com/classes/">Classes</a></li>
<li id="menu-item-60" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-60"><a title="Contact" href="http://mysite.com/contact/">Contact</a></li>
</ul>
</div>
</ul>
</div>
</div>
</div>
Thank you so much. Again, I really do appreciate your help.
I hope you don't mind me asking another question? What am I doing incorrectly for the parent menu item to have a link value of "#" instead of the actual address?
from wp-bootstrap-navwalker.
I created a CodePen and loaded the default Bootstrap 3.0.3 CSS & JS and the HTML output by the walker is a valid Bootstrap menu with a working dropdown.
http://codepen.io/twittem/pen/lwbjC
This tells me thats the function you are using to load the bootstrap JS is probably throwing an error. Could you share the function that loads your JS from your functions.php
As for your other question, you are doing nothing wrong... the walker eliminates the top level link... as top level links for drop downs are not supported with Bootstrap. This is because with Bootstrap you must click to open the dropdown. This is to facilitate touch devices (this can be a phone tablet, laptop or desktop these days) and without it there is no way to access your dropdown items. I would suggest eliminating the top level page (as they are often redundant) or moving the information to a single page. Just an FYI as of Bootstrap 3.0 it also only supports one level of dropdown for the same reasons.
from wp-bootstrap-navwalker.
You're correct twittem! Turns out, everything is fine with the navwalker & dropdown js. The problem was with the bootstrap js being loaded twice (separate files). I removed the excess code, & everything is now working fine. (Don't know how I overlooked that!)
Thank you for all your help and information on the top level links (+ the prompt responses). It's greatly appreciated!
from wp-bootstrap-navwalker.
No problem, I am glad everything worked out for you!
from wp-bootstrap-navwalker.
Hey, sorry to re open this issue, but for me it isn't working on codepen... even the one provided by @twittem here seems broken... is this codepen related?
from wp-bootstrap-navwalker.
Seems that both this original issue and the recent one (sorry for missing this recent issue BTW) are script loading related.
Should there be a note in the readme.MD file about loading the core files? Since navwalker assumes those to be loaded anyway I don't think it's mentioned anywhere. Perhaps if it was mentioned both these issues could have been prevented and/or resolved more quickly?
from wp-bootstrap-navwalker.
As @Earth2Andy comments, bootstrap's js has to be loaded as well on the js tab. That solved my issue but forgot to post the update.... anyway, perhaps codepen should warn the user when adding bootstrap, as it seems counterintuitive that you have to include it in two different tabs
from wp-bootstrap-navwalker.
@Earth2Andy Thank you so much that fixed my problem. I had both loaded but after loading them in the order you specified it worked!
from wp-bootstrap-navwalker.
Ive been trying to use it on codepen for hours....thank you so much guys.Pretty backwards having to add bootstrap twice...
from wp-bootstrap-navwalker.
Related Issues (20)
- What is `WP_Nav_Menu_Args` and `WP_Nav_Menu_Item`? HOT 5
- Scroll mobile menu HOT 6
- Useless PHP unit tests for multisites?
- Third Level menu works, but it needs toggle icon in mobile to avoid hover problem
- Navwalker dropdown doesn't remain open on click HOT 5
- How to add an additional first item to all dropdown without using wordpress menu management. HOT 7
- Grant repo access to IanDelMar HOT 3
- Skipping data-toggle attribute and dropdown-toggle class (for mobile and tablet viewports) HOT 3
- Bootstrap 5 - How to make parent dropdown links clickable instead of # HOT 2
- Duplicate / Repeat parent menu item as first item in child menu HOT 4
- Menu button disappears when clicked HOT 8
- Active Class Font Color Not Working HOT 3
- WP Bootstrap Nav walker disappeared after reloading template HOT 3
- How to Display sub items if the Menu first level is Category selected?
- Dropdown is not working HOT 36
- How can I modify the closing li tag HOT 1
- Warning: Array to string conversion on line 149 in PHP 8.2
- Dropdown exit Animation HOT 1
- Link with dropdown associated to a page contains no URL but a #. HOT 1
- Mobile menu nog showing HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wp-bootstrap-navwalker.