Open sptutusukanta opened 6 years ago
navigation alignment happens in the UL element, where are your classes for that element?
Yes, I know it is required to put the alignment class in the <ul>
element. But, how can I put that?
I placed it in the class field of menu in WP's menu editor. But, it renders inside parent <li>
.
My expection is to get something like this:
<li ... class=" ... dropdown ... ">
<ul class="dropdown-menu dropdown-menu-right" ... >
<li>...</li>
<li>...</li>
...
</ul>
</li>
But I'm geting it like this:
<li ... class="dropdown-menu-right ... dropdown ... ">
<ul class="dropdown-menu" ... >
<li>...</li>
<li>...</li>
...
</ul>
</li>
You may check my previous post to see the full output. Here I've just pointed the main elements.
How can I achieve this from WP's menu editor? Is it supported? Or any workaround is strongly appreciated.
I just double checked your menu HTML, to clarify are you using Bootstrap 3? That looks like a Bootstrap 3 as bootstrap 4 containers are now div's with a list of the anchors.
https://getbootstrap.com/docs/4.0/components/navs/#using-dropdowns
The current walker is BS4, which may be why you're having a problem.
There's a BSWalker v3 branch in the branch drop-down, see if that fixes your problem.
@sptutusukanta My solution is by using Sass or CSS. On my case, I'm extending the class .dropdown-menu-right
whenever I have a .navbar-nav.ml-auto
.
.navbar-nav.ml-auto{
.dropdown-menu{
@extend .dropdown-menu-right;
}
}
I had the same problem. Would be awesome if there was a way to tell the navwalker, if a dropdown-menu-right
or dropdown-menu-left
is wanted. But I must admit that I can't see where that would be declared.
I tried @earvinpiamonte 's suggestion, but couldn't get it to work. I solved it by doing this (in my SASS/CSS):
.dropdown-menu {
left: auto;
right: 0;
}
I will be looking at enabling this with an easier method in the upcoming version of the walker (I hope to be working on it over the next 3 or 4 weeks).
EDIT: $classes
is passed as an array of values, not as a string like I originally posted. I have updated the code below.
For the moment one way to go about doing this would be to use the nav_menu_submenu_css_class
, which will receive a string array of classes in it's first parameter. You can use that filter to add the class for the sidedness of choice.
function filter_add_dropdown_side_right( $classes ) {
$classes[] = 'dropdown-menu-right';
}
add_filter( 'nav_menu_submenu_css_class', 'filter_add_dropdown_side_right' );
I needed to align the dropdown menu to the right, by default it is on the left. As with bootstrap, we use
.dropdown-menu-right
class along with.dropdown-menu
to align dropdown menu.I tried to use it in menu class in admin panel, as expected it is populating in the parent
<li>
tag. Is there any other way to put this class from admin panel?Here is the expected output as per Bootstrap's documentation:
Here is what I got add the class to menu from admin:
This is clear here, the class
.dropdown-menu-right
is placed to the parent<li>
tag, not with the<ul>
dropdown.