[Support request] Secondary menu appears on mobile when it should not

Home Forums Support [Support request] Secondary menu appears on mobile when it should not

Home Forums Support Secondary menu appears on mobile when it should not

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1056618
    Gilles

    Hello
    I can not fix a problem with the secondary menu.
    This menu should only appear for logged in users. For that I use the plugin ifmenu (https://fr.wordpress.org/plugins/if-menu/): https://i.imgur.com/5pe09Vr.jpg
    It’s OK on Destock Device: https://i.imgur.com/lRuUfgk.jpg
    But, on mobile device, secondary menu appears (but is inactive) as you can see here (https://i.imgur.com/BpQdylT.png) even if user is not logged in …
    I would like it not to appear on a mobile device if the user is not logged in (But that it appears well if it is connected… so I can’t use mobile restriction with ifmenu )
    Could you help me ?
    Thank you
    Regards
    Gilles Dubus

    #1056733
    David
    Staff
    Customer Support

    Hi there,

    If Menu only removes the menu items themselves not the container.
    Two options:

    1. Some CSS to hide the secondary nav container on mobile:

    @media (max-width: 768px) {
        .secondary-navigation {
            display: none;
        }
    }

    2. If it is the entire navigation that should only be visible to logged in users then you can remove IF Menu and instead use the Layout Element to Disable the secondary navigation. Within the Display Rules you can set Logged Out users.

    #1056775
    Gilles

    Thank you for your answer David.

    1) The secondary menu must be visible to logged in users, so it is not suitable.
    2) I don’t understand how to do it…

    But never find… I finally found the solution in your documentation : https://docs.generatepress.com/article/show-secondary-navigation-to-logged-in-users-only/ :

    add_filter( ‘has_nav_menu’, ‘tu_disable_secondary_nav_logged_out’, 10, 2 );
    function tu_disable_secondary_nav_logged_out( $has_nav_menu, $location ) {
    if ( ‘secondary’ === $location && ! is_user_logged_in() ) {
    return false;
    }

    return $has_nav_menu;
    }

    I put this code in the theme functions.php file and it works perfectly.

    Best regards
    Gilles

    #1056780
    David
    Staff
    Customer Support

    To explain 2:
    Using the Layout Element:
    https://docs.generatepress.com/article/layout-element-overview/

    You can Disable Secondary Navigation then in your Display Rules set it to logged out users. This will then remove the nav for any logged out user.

    Which is doing exactly what that PHP filter snippet is doing 🙂

    Glad you found the solution

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