Site logo

Archived topic

Dropdowns on generate_menu_bar_items hook

5 replies · Started by Keith Taylor on March 8, 2022

Viewing posts 1–6 of 6

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/

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

This archived topic is closed to new replies.