Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

sticky secondary navigation

  • Dear –

    Trying to copy the secondary menu from Apple website :
    https://www.apple.com/imac/

    Some details :
    – Text on the left + Link with CTA on the right
    – Highlight the curent page
    – Only on desktop
    – Sticky when scrolling
    – Different secondary menu item from from one section to another

    Would you able to guide me to achieve this ?

    thx

  • Hi there,

    can you explain this ?

    Different secondary menu item from from one section to another

    And can you share a link to the site you want to apply this to ?

  • here it is

    what I meant by Different secondary menu item from from one section to another is that from
    There are 2 sections with different content in each secondary menu
    https://www.apple.com/imac/
    https://www.apple.com/ipad-pro/

    link to the site : https://le-briand.fr/

    thx

  • 1. Enable secondary nav at customzier > layout > secondary navigation, set navigation location to below header.

    2. Create multiple menus at appearance > menus for your secondary nav for different pages.

    3. Use this PHP code to switch menus for secondary nav on different pages, note that the 1 of $args['menu'] = 1; is the menu ID, you can find the ID in the URL when editing a menu.

    add_filter( 'wp_nav_menu_args', function ( $args ) {
        // if the menu is the secondary menu && is page with ID 100
        if ( 'secondary' === $args['theme_location'] && is_page(100)  ) {
                $args['menu'] = 1;
        }// if the menu is the secondary menu && is page with ID 200
        if ( 'secondary' === $args['theme_location'] && is_page(200)  ) {
                $args['menu'] = 2;
        }// if the menu is the secondary menu && is page with ID 300
        if ( 'secondary' === $args['theme_location'] && is_page(300)  ) {
                $args['menu'] = 3;
        }// you can keep on adding conditional for more pages and more menus
        return $args;
    } );

    4. To add the CTA button, create a block element – hook, set hook to inside_secondary_navigation, location to entire site, and set the order of the button block to 10 so it sits at the end of the secondary nav.

    5. To add the different text on the left, you need to create multiple block element – hook, set the hook to inside_secondary_navigation as well, but location to different pages. And select the headline block, set margin-right to auto to push the menu and CTA button to the right.

    6. To stick the secondary nav, add this CSS:

    nav#secondary-navigation {
        position: sticky;
        top: 0;
    }
  • thx.

    Got it.

    Work in progress

    How do we hide the secondary navigation for screen under 768px?

    thx

  • almost there : https://le-briand.fr/sommier-tapissier/

    need help on some details :
    – Vertically aligned the title section “Sommier Tapissier”
    – Move the CTA “Estimer la fabrication de matelas” to the far right, on the right side of the 3 items menu (Introduction / Fabrication / Réfection)
    – Align the text and the arrow icon in the CTA

    thx

  • last question :

    the secondary nav is set to be displayed on only 3 pages but it displays on all website (like homepage : https://le-briand.fr/).
    I would the menu to be displayed on only 3 pages for now.

     /* Switch menus for secondary nav on different pages */
    add_filter( 'wp_nav_menu_args', function ( $args ) {
        // if the menu is the secondary menu && is page with ID 100
        if ( 'secondary' === $args['theme_location'] && is_page(8191) && is_page(43) && is_page(3865) ) {
                $args['menu'] = 61;
        }// you can keep on adding conditional for more pages and more menus
        return $args;
    } );

    What should I change ?

    thx

  • – Vertically aligned the title section “Sommier Tapissier”
    Select the headline Sommier Tapissier, set margin-bottom to 0, remove margin-top.

    – Move the CTA “Estimer la fabrication de matelas” to the far right, on the right side of the 3 items menu (Introduction / Fabrication / Réfection)
    In the element, select the container, set order to 10 in the layout panel > flex child.

    – Align the text and the arrow icon in the CTA
    Select the button block, set display to flex, align-items to center.

  • You can use a layout element to disable secondary nav for front page.
    https://docs.generatepress.com/article/layout-element-overview/#disable-element

  • thx

    1- I would like to set the secondary navigation ONLY on the pages listed on the script
    The other should be without secondary navigation.
    Disabling page by page (https://docs.generatepress.com/article/layout-element-overview/#disable-element) is way too time-consuming. Any other solution ?

     /* Switch menus for secondary nav on different pages */
    add_filter( 'wp_nav_menu_args', function ( $args ) {
        // if the menu is the secondary menu && is page with ID 100
        if ( 'secondary' === $args['theme_location'] && is_page(8191) && is_page(43) && is_page(3865) ) {
                $args['menu'] = 61;
        }// you can keep on adding conditional for more pages and more menus
        return $args;
    } );

    2- In the element, select the container, set order to 10 in the layout panel > flex child to move the CTA “Estimer la fabrication de sommier” to the far right, on the right side of the 3 items menu (Introduction / Fabrication / Réfection)
    But it does work. Can you help?

    3- How do we hide the secondary navigation for screen under 768px?

    thx

  • Hi there,

    1. Using the Layout Element to hide the secondary navigation is super easy and not time-consuming. Just follow these steps:

    Create a new Layout Element, then on the Disable Elements tab, check the Secondary Navigation. Then go to Display Rules, set the Location to Entire Site, on Exclude choose Page and select the page that you want the secondary navigation to show.

    2. Do you mean it doesn’t work? Have you applied the settings on the current page?

    3. Use this CSS:

    @media (max-width: 768px) {
      nav#secondary-navigation {
        display: none;
      }
    }
  • thx Alvind

    almost there : https://le-briand.fr/sommier-tapissier/

    need help on some details :
    – How can we move the 3 items menu (Introduction / Fabrication / Réfection) by the CTA “Estimer la fabrication de sommier”

    thx.

  • Hi there,

    try this CSS:

    
    nav.secondary-navigation .main-nav {
        margin-left: auto;
        margin-right: 20px;
    }
    
  • thx.

    I tried the PHP script to switch menus for secondary nav on different pages.
    But it doesn’t work.

    Example :
    ID : 8191 -> https://le-briand.fr/sommier-tapissier/
    ID : 8493 -> https://le-briand.fr/matelas-laine/

     /* Switch menus for secondary nav on different pages */
    add_filter( 'wp_nav_menu_args', function ( $args ) {
        // if the menu is the secondary menu && is page with ID 100
        if ( 'secondary' === $args['theme_location'] && is_page(8191) ) {
                $args['menu'] = 61;
    	}
    	if ( 'secondary' === $args['theme_location'] && is_page(43) ) {
                $args['menu'] = 61;
    	}
    	if ( 'secondary' === $args['theme_location'] && is_page(3865) ) {
                $args['menu'] = 61;
    	}
    	if ( 'secondary' === $args['theme_location'] && is_page(41) ) {
                $args['menu'] = 63;
        }
    	if ( 'secondary' === $args['theme_location'] && is_page(8393) ) {
                $args['menu'] = 63;
        }
    	if ( 'secondary' === $args['theme_location'] && is_page(7073) ) {
                $args['menu'] = 63;
        }
    	if ( 'secondary' === $args['theme_location'] && is_page(10546) ) {
                $args['menu'] = 63;
        }// you can keep on adding conditional for more pages and more menus
        return $args;
    } );

    What would be the solution ?

    thx

  • I’m not seeing the secondary navigation on both pages you linked. Did you disable the secondary nav?

    And your code can be simplified as:

    add_filter( 'wp_nav_menu_args', function ( $args ) {
        // If the menu is the secondary menu and is on pages with specific IDs
        if ( 'secondary' === $args['theme_location'] ) {
            if ( is_page( array( 8191, 43, 3865 ) ) ) {
                $args['menu'] = 61;
            }
            
            if ( is_page( array( 41, 8393, 7073, 10546 ) ) ) {
                $args['menu'] = 63;
            }
        }
        // You can keep adding conditionals for more pages and more menus
        return $args;
    } );
    
  • I add the code on the functions.php of the child theme.

    I active the secondary menu on generatedPress side.

    I enable the secondary nav by removing all the Layout Element to hide the secondary navigation.

    I create the 2 different menus with the ID 63 and 61 on Appearance > Menu.

    When I start to set location (in Appearance > Menu > Menu Settings) of one of these 2 menus, it shows up everywhere.

    And I can’t set the 2 menus I created as Secondary Menu.

    Example : on these pages, the secondary menu items should be differents, but they are the same at the moment.
    ID : 8191 -> https://le-briand.fr/sommier-tapissier/
    ID : 8493 -> https://le-briand.fr/matelas-laine/

    How can I slove the issue ?

    thx

Viewing 16 posts - 1 through 16 (of 19 total)
  • You must be logged in to reply to this topic.