I tried to achive this using the next code
function my_wp_nav_menu_args( $args = ” ) {
if( is_user_logged_in() ) {
$args[‘menu’] = ‘user’;
} else {
$args[‘menu’] = ‘no-user’;
}
return $args;
}
add_filter( ‘wp_nav_menu_args’, ‘my_wp_nav_menu_args’ );
The problem is that function modify every menu I just want to modify primary.
Read more here:: Display different primary menu based in login status