Archived topic
Different main menu for logged in users
5 replies · Started by Michael on November 27, 2020
Hello,
I wish to use a different main menu for logged in users.
adding this snippet works but it also changes my other navigation menus.
add_filter( 'wp_nav_menu_args', function( $args ) {
if ( is_user_logged_in() ) {
$args['menu'] = 'Main2';
} else {
$args['menu'] = 'Main';
}
return $args;
} );
I'm trying to avoid using a plugin
thanks!
Hi there,
you can set a condition for the Theme Location , for example this would apply to the Primary Nav:
add_filter( 'wp_nav_menu_args', function ( $args ) {
if ( 'primary' === $args['theme_location'] ) {
if ( is_user_logged_in() ) {
$args['menu'] = 'Main2';
} else {
$args['menu'] = 'Main';
}
}
return $args;
} );
That did the trick! thanks, David.
I also plan to do the same for the Off Canvas Menu. Could you tell me how to target that as well?
The off canvas panel has a theme location of: slideout so this condition:
if ( 'primary' === $args['theme_location'] ) {
becomes:
if ( 'slideout' === $args['theme_location'] ) {
That worked. thanks!
Glad to be of help