Archived topic
Dropdowns on generate_menu_bar_items hook
5 replies · Started by Keith Taylor on March 8, 2022
Hi
Is it possible to have a link that I add with the generate_menu_bar_items hook to have a dropdown to a secondary menu? I'm trying to get a login link there that changes to "Account" with a dropdown when the user is logged in.
I thought of using secondary nav, but can't see an option to position this on the same horizontal as the main nav.
Many thanks.
Hi there,
if you have no other use for the Secondary navigation then do the following:
1. Create a new Hook Element in Appearance > Elements
2. Add this code to the Hooks text area:
<div class="second-nav grid-container">
<?php
if ( function_exists( 'generate_secondary_navigation_position' ) ) {
generate_secondary_navigation_position();
}
?>
</div>
3. Set the Hook to: generate_menu_bar_items
4. Check Execute PHP and set your Display Rules.
That will place the secondary nav in the menu bar items.
5. Assign a menu to the Secondary Nav.
6. Set the Customizer > Layout > Secondary Navigation --> Location to No Navigation. This will remove the one the them outputs.
Not sure what your intentions are for mobile, but this article explains how to stop it from turning into a hamburger:
https://docs.generatepress.com/article/disable-secondary-navigation-mobile-menu/
Thanks David, this works perfectly to get the secondary nav inside the menu bar items.
The only thing I can't get to work is to stop the secondary nav menu turning in to a hamburger.
I've followed the instructions at https://docs.generatepress.com/article/disable-secondary-navigation-mobile-menu/ but can't work out what I'm doing wrong.
Many thanks
Keith
The CSS in that Doc may require a little !importance - try this:
.secondary-navigation .menu-toggle {
display: none !important;
}
@media(max-width: 10248px) {
.secondary-navigation {
text-align: center !important;
}
.secondary-navigation ul {
display: block !important;
}
.secondary-navigation .sf-menu>li {
float: none;
display: inline-block !important;
}
}
Great, that did it, thanks :-)
Glad to hear that