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.

different menu

  • hello,
    is it possible to create 2 different navigations where they appear on different pages on desktop and mobile?
    There are 2 different locations on the website and they each have a different menu.
    I would be very grateful for your help

  • Yes, you can create 2 different menus, and get their ID which can be found in the URL when you edit the menu.

    Here’s the PHP code which activates ID 10 menu on ID 100 page, and ID 20 menu on ID 200 page, you need to switch the menu IDs and page IDs to the actual ones.

    add_filter( 'wp_nav_menu_args', function ( $args ) {
        if ( 'primary' === $args['theme_location']  && is_page( 100 ) ){
            $args['menu'] = 10;
        }
        if ( 'primary' === $args['theme_location']  && is_page( 200 ) ){
            $args['menu'] = 20;
        }
    
        return $args;
    } );
  • great thanks and it works.
    Should I better not set either of the two navigations as primary? And another question about the spelling:
    i want to add several pages to a menu, unfortunately the spelling is not correct, if you could still show me the correct one here! Many thanks in advance?

    add_filter( ‘wp_nav_menu_args’, function ( $args ) {
    if ( ‘primary’ === $args[‘theme_location’] && is_page( 100 ) ){
    $args[‘menu’] = 2;
    }
    if ( ‘primary’ === $args[‘theme_location’] && is_page( 1366, 1477 ) ){
    $args[‘menu’] = 7;
    }

    return $args;
    } );

  • Hi there,

    the best option would be to choose one menu as the default menu and set its Location to the Primary Menu.

    Then just add a function to replace that menu where you require it eg.

    
    add_filter( 'wp_nav_menu_args', function ( $args ) {
        if ( 'primary' === $args['theme_location']  && is_page( 1366, 1477 ) ){
            $args['menu'] = 7;
        }
    
        return $args;
    } );
    
  • thank you and it works perfect!

  • glad to hear that !

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