Skip to:
Content
Pages
Categories
Search
Top
Bottom

Can’t show any menu except for my logged in menu


  • andrewwebber25
    Participant

    @andrewwebber25

    So I found the source of my problem possibly but Im not sure how to change it. I have my Primary Menu set to a menu called Logged In. Another menu I have is called Logged Out. I wanted a returning user to get the Logged In menu which has all the items in the nav bar. If its a new, non signed in user accessing the site, they get the Logged Out menu (this nav menu has far less items on it). This is the code that I have to check if users accessing the site are logged in or not.

    /*To swap between two different menues. One for logged in users, one for logged out*/
    function my_wp_nav_menu_args( $args = '' ) {
     
    if( is_user_logged_in() ) { 
        $args['menu'] = 'Logged In';
    } else { 
        $args['menu'] = 'Logged Out';
    } 
        return $args;
    }
    add_filter( 'wp_nav_menu_args', 'my_wp_nav_menu_args' );
    

    The code works perfect. I realized that every new menu I create though, it still only shows the Logged In menu it its place. For ex, the Logged In menu has the Notifications Page link (obviously the Logged Out menu would not as no account is active). I decided I wanted Notifications to be its own menu so I could put it in the top right of the site, separate from everything else. I made a new menu called Test and just put the Notification page in it. Then I put the Test menu in its own spot. When I publish it though, now I have two Logged In menus. If I delete the code above, then everything looks correct (but logged out users get the Logged In Primary Menu then).

    Something to note is that my theme only comes with the primary menu option and nothing else. I added code to create a second menu option. When I dropped the Test Menu into that spot it still just showed the Logged In menu twice. So is there a way to change the above code that it still operated properly but also doesnt interfere with every menu I try to create in the future? The above code is located in my wp-content/themes/customify/functions.php section. Im really sorry if I wording this poorly. Any advice for the problem is appreciated!

  • You must be logged in to reply to this topic.
Skip to toolbar