How do I make Primary Menu Conditional in News Theme ?

Community Forums Forums General Discussion How do I make Primary Menu Conditional in News Theme ?

This topic is: not resolved

This topic contains 6 replies, has 2 voices, and was last updated by  Strangeman 2 years, 2 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
  • #44048


    I am trying to make a different Primary Menu appear if a user is logged in

    I have registered a new menu type in functions.php


    register_nav_menus( array(
            'primary' => __( 'Primary Navigation', 'news' ),
            'members' => __( 'Members Only Navigation', 'news' ),
        ) );
    and then I got stuck on where to apply the conditional code to make the members menu replace the primary menu.
    Or is that more complex than needs be and should I just be changing the Primary menu itself for a logged in user?



    Almost correct.  Here is what I came up with;

    If someone else has a more elegant method, feel free to speak up.

    I hope this works.

    Let me know how it turns out.



    Hey Ryan,

    Thanks for posting that code – it works really well … except that there was no Primary menu if the visitor is not logged in

    however when I changed the first couple of lines to this


    // add the members menu through Genesis menu support
    add_theme_support( ‘genesis-menus’, array(
    ‘primary’ => __( ‘Primary Navigation’, ‘news’ ),
    ‘members’ => __( ‘Members Only Navigation’, ‘news’ ),
    ) );


    It worked exactly as I wanted – thank you so much for your help!



    I’m glad you found a solution.



    Is there a similar approach which I could use to populate a sidebar with widget(s) after a user has logged in ?




    If you have two sidebars, one for non-authenticated users and authenticated users, you could add your own custom genesis sidebar hook and fallback to the default one.

    // remove the default sidebar callback
    remove_action( ‘genesis_sidebar’, ‘genesis_do_sidebar’ );
    add_action( ‘genesis_sidebar’, ‘custom_genesis_do_sidebar’ );
     * Callback for Genesis Framework ‘genesis_sidebar’ action.
     * If the user is not logged in, display the default side, else 
     * display the other (authenticated) sidebar, with the default as 
     * a fallback.
    function custom_genesis_do_sidebar(){
    	// if the user is not logged in…
    	if( ! is_user_logged_in() ){
    		// show fallback (non-authenticated) sidebar
    		// exit the function
    	// display authenticated sidebar
    	if ( ! dynamic_sidebar( ‘auth-sidebar’ ) ) {
    		// fallback to default non-authenticated sidebar

    This is what I came up with. I am sure there are probably a few ways to do this and maybe a plugin or two that could do the same.

    Good luck.



    Hey Ryan, again, (and anyone else who might be interested)

    Thanks for posting all that info back then, it produced a much simpler solution than having to install some overblown membersite plugin.

    However …. just had a call from the owner of the first website I put this on to say that the menu has disappeared from her website ! At the moment it’s looking like something in the upgrade to genesis 2.0.1 has produced this problem, so while I go about setting up a duplicate local site to test, I thought I’d post here and see whether you might know of a reason why 2.0.1 might have broken your code snippet (for the menu)

    cheers Alan

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.