Skip to:
Content
Pages
Categories
Search
Top
Bottom

Different naviagtion menu for logged out/non registered users


  • agizzie
    Participant

    @agizzie

    latest WP & BP using Community Builder theme…
    I’m trying to set 2 differetn menus. first is for logged out users, basically registration page with login button. And once logged in >full menu. I’ve set up both menus via dashboard.

    Here’s what code I have tried in functions.php:

    // Conditional Nav Menu
    
    function wpc_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', 'wpc_wp_nav_menu_args' );

    Above works however, it changes all menus I’m looking for just top/main nav

    // Conditional Nav Menu
    
    function wpc_wp_nav_menu_args( $args = '' ) {
    if( is_user_logged_in()) { 
      	if( 'top-navigation' == $args['theme_location'] ) { // Change top-navigation to theme specific name
    	    $args['menu'] = 'logged-in';
    	}
    } else { 
    	if( 'top-navigation' == $args['theme_location'] ) { // Change top-navigation to theme specific name
    	    $args['menu'] = 'logged-out';
    	}
    } 
        return $args;
    }
    add_filter( 'wp_nav_menu_args', 'wpc_wp_nav_menu_args' );

    Above does nothing. I can’t find what my theme calls the main nav to check if using top-navigation.

    Any ideas??

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