Show a different menu for logged in and logged out users.

When running a WordPress membership site, a forum in WordPress, or allowing users to submit posts, you may come across situations where you want to show different navigation menus to logged in and logged out users. For example, you may want to show logged in users a link to their profile and a link to sign in or register for users who are not logged in. In this article, we will show you how to show different menus to logged in users in WordPress.

Create 2 menus, one called logged-in and one called logged-out.

then add this to the functions.php file.

// Set for logged in and logged out users
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’ );
// Set for logged in and logged out users END

Leave a Comment


Important This site makes use of cookies which may contain tracking information about visitors. By continuing to browse this site you agree to our use of cookies.