Site logo

[Support request] How to REPLACE the primary menu for logged in users

Home Forums Support [Support request] How to REPLACE the primary menu for logged in users

Home Forums Support How to REPLACE the primary menu for logged in users

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #2438859
    Wesley

    Hi, I have a problem that I’ve tried for hours to resolve by reading different posts here, but I’m still at a loss.

    For logged in users, I’m looking to complete replace the main header navigation.

    Here is a video with more detail:

    https://www.loom.com/share/6140e785087e48429f9607356dcb6c07

    Hope you can help.

    Thanks
    Wesley

    #2438959
    David
    Staff
    Customer Support

    Hi there,

    instead of hooking in the secondary navigation and dealing with a whole bunch of different HTML and Customizer settings as well as GP hooks, the simplest option maybe to swap the Menus using this PHP Snippet:

    add_filter( 'wp_nav_menu_args', function ( $args ) {
        if ( 'primary' === $args['theme_location'] ) {
            if ( is_user_logged_in() ) {
                $args['menu'] = 'LOGGED IN';
            } else {
                $args['menu'] = 'LOGGED OUT';
            }
        }
        return $args;
    } );
    #2439235
    Wesley

    Sorry if this is a dumb question, David.

    Can you clarify where I place that PHP snippet?

    Thanks,
    Wesley

    #2439248
    David
    Staff
    Customer Support

    Sorry – i should have provided this doc, which explains:

    https://docs.generatepress.com/article/adding-php/

    TLDR:
    Are you using a Child Theme?
    If Yes, then you can add the snippet to your child theme functions.php file
    If No, then use the Code Snippets plugin ( link in the above doc ) and add it to a New Snippet.

    #2439312
    Wesley

    Awesome. It works.

    I’m eternally grateful, David.

    Have a great week.

    Wesley

    #2439436
    David
    Staff
    Customer Support

    Glad to be of help!

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