Site logo

Archived topic

Move secondary navigation to other locations

21 replies · Started by Paul on September 26, 2015

Viewing posts 1–15 of 22

Hi Tom,

I'd like to move my secondary navigation to other parts of a page other than just above or below the site header. In this case, I'd like to embed the secondary navigation bar into a page section on my home page only, perhaps with use of a shortcode. What would be the best practice for accomplishing this?

Hi Paul,

You could try creating a shortcode (not 100% sure it will work).

function generate_secondary_navigation_shortcode() {
      return generate_secondary_navigation_position();
}
add_shortcode( 'generate_secondary_navigation', 'generate_secondary_navigation_shortcode' );

Adding PHP: https://generatepress.com/knowledgebase/adding-php-functions/

Then you might be able to use the [generate_navigation] shortcode in your Sections.

Worked like a charm, Tom.

For anyone wanting to do this also, I just:
1) pasted Tom's code into my GP child theme's functions.php file
2) added [generate_secondary_navigation] to a section on the page (in my case section 2)
3) double-checked that Secondary Navigation was not checked in the Disable Elements box
4) clicked Update

That made the secondary nav appear twice on the page: one above the header, and one in the section where I really wanted it.

To hide the unwanted secondary nav appearing in the header, I used the following CSS in my GP child theme style.css file:

.main-nav {
	display: none;
}
#generate-section-2 .main-nav {
	display: block !important; 
}

Be sure the change #generate-section-2 in the code above to reflect the number of the section you're actually using the shortcode in.

Awesome, glad that worked for you :)

Oops, one error.

.main-nav in the above CSS needs to be replaced with #menu-second-menu so the links in the primary navigation don't disappear!

I would use this instead:

.secondary-navigation {
	display: none;
}
#generate-section-2 .secondary-navigation {
	display: block !important; 
}

Cool beans. I made the changes and they're working fine. Thanks for the suggestion!

No problem!

Well, I thought it worked. When viewing the secondary nav on mobile devices, the drop-down menu doesn't work. The mobile icon and menu name appears, but not the drop-down which is supposed to show the sub-pages. Do I need to add additional code to what you suggested to functions.php?

Can you link me to the page possibly?

It's on localhost only right now.

Ok - I'll try and find some time in the morning to put it into a shortcode and do some testing.

I'll get back to you :)

Just had a thought: could it have to do with z-index? Perhaps the drop-down IS happening, but is being obscured by the following section. Or maybe it is not increasing the height of the section that it's contained in so as to be viewable? Not sure how to tell if either is occurring though. Hmmm.

It had to do with overflow.

Try this CSS:

.site-main .inside-navigation {
    margin: 0;
    overflow: visible;
}

Gave it a try, but no go. FWIW, I am using Menu Plus. Not sure if that makes any difference though. The secondary nav does work in it's typical positions above and below the site header, just not as a short code in a page section, which is where I need it.

I'm wondering if anything is missing from the shortcode that I pasted into functions.php?

This archived topic is closed to new replies.