• Resolved billoh

    (@billoh)


    I’m building a members-only site that requires a different navigation menu once one is signed in. I have created the two menus that I want, but can’t seem to figure out how to assign the menus to the pages in the header/footer areas on a per page basis.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi @billoh,

    I would recommend creating an MU plugin. We’ve got a tutorial setup in our documentation: https://godaddy.github.io/wp-primer-theme/tutorials-and-examples/tutorials/mu-plugin.html

    Once you have your MU plugin setup, you can add the following bit of code to it, and update the number beside the ‘menu’ parameter.:

    /**
     * Display a custom menu for logged in users.
     *
     * @return mixed Markup for the nav menu.
     */
    function primer_logged_in_nav_menu() {
    
    	if ( ! is_user_logged_in() ) {
    
    		return;
    
    	}
    
    	remove_action( 'primer_site_navigation', 'primer_add_primary_menu' );
    
    	add_action( 'primer_site_navigation', function() {
    		wp_nav_menu(
    			array(
    				'menu'   => 4,
    				'walker' => new Primer_Walker_Nav_Menu,
    			)
    		);
    	} );
    
    }
    add_action( 'template_redirect', 'primer_logged_in_nav' );

    The number next to menu is the ID of the menu you want to display to the logged in users. If you are not logged in you will still see the default menu. You can retrieve this number from the URL bar on the edit menu page.

    Example:
    Screen Shot

    You’ll notice that in the URL I have menu=4. Your ID may be different. When you’ve updated the ID in the code snippet, you can save the file. The menus should then switch out depending on the logged in state of the user.

    Let us know how that goes for you.

    Evan

    Thread Starter billoh

    (@billoh)

    Thanks for this. I will let you know. But it will take a while for me to digest it as I’m quite the novice. And I do SEEM to have it partially working utilizing some features of the Ultimate Member plug-in.

    Thanks again

    Bill

    Thread Starter billoh

    (@billoh)

    Hi Evan

    I managed to get what I needed accomplished by using features built into the Ultimate Member plug-in, which I’m using anyway. I did build a mu-plugin script, though, as it does seem to be something that might be used as I go on. I did use your script also, but got myself quite confused until I realized that UM and your script were both trying to do the same thing at the same time and I was having a hard time remembering what I was actually testing at any particular moment!

    Thanks for the help and the quick response.

    Bill O’H

    No problem at all, glad to help out in any way that I can! Have a great weekend.

    Evan

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘using different menus on different pages’ is closed to new replies.