How to get active menu class in wordpress, I want to get it in one plugin to change menu style.
Just to clear, I do not want active menu element class.
<ul id="menu-scroll" class="nav-menu">
<li id="menu-item-1461" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-1461"><a href="#home">Home</a></li>
<li id="menu-item-1462" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-1462"><a href="#about">About</a></li>
<li id="menu-item-1463" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-1463"><a href="#services">Services</a></li>
<li id="menu-item-1466" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-1466"><a href="#team">Team</a></li>
<li id="menu-item-1468" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-1468"><a href="#blog">Blog</a></li>
<li id="menu-item-1467" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-1467"><a href="#contact">Contact</a></li>
</ul>
In this I want to get “nav-menu” or i want to set new class like
<ul id="menu-scroll" class="my-nav-menu">
But not using themes file, I want to work it for all theme which is active.
Thanks In Advance,
Ajay
This is relatively easily done with a filter.
That will make this line:
Look like this one:
But that could cause themes to break horribly. If a theme has used that class to apply styles to the menu, which would be a reasonable thing to do, you’ve just broken all of that styling. The effected menus will look terrible and may not even function. This is a very, very bad idea. Please don’t do it.
This is the following safer way to add class to nav menu wrapper as it will not overwrite existing class.
The following code adds custom class to nav menu ul tag