• Resolved bastibln

    (@bastibln)


    Hey,
    I am using the Gridbox Pro Theme and I added the following code into the functions.php to have two different menus: one for logged-in Users and one for logged-out visitors.

    function my_wp_nav_menu_args( $args = '' ) {
    
    if( is_user_logged_in() ) { 
        $args['menu'] = 'Hauptmenü_LoggedIn';
    } else { 
        $args['menu'] = 'Hauptmenü_LoggedOut';
    } 
        return $args;
    }
    add_filter( 'wp_nav_menu_args', 'my_wp_nav_menu_args' );

    This code solves my main issue of having two different menus, but it automatically transfers the footer menu as well. I thus need an improvement for isolating this if-clause for only the main menu on top.

    Note: I already tried to get an answer from a different question in this forum, but the suggested solution doesn’t work on my project. Here is this code:

    /* Menu for logged in and out users */
    function prefix_main_menu_location() {
    
    	$return = 'main_menu';
    
    	if( is_user_logged_in() ) { 
    		$return = 'logged_in';
    	} else {
    		$return = 'logged_out';
    	}
    
    	return $return;
    
    }
    add_filter( 'ocean_main_menu_location', 'prefix_main_menu_location' );

    Thanks for the help and stay healthy.

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Created different menus for logged in users but cannot isolate main menu’ is closed to new replies.