Display Different WordPress Menu to Logged in Users

Display Different WordPress Menu to Logged in Users

When creating a WordPress website you may run into scenarios where you would like to display different WordPress menus depending on if a WordPress User is Logged In or Logged Out.

For example. you may have a WordPress membership site and you would like to display different WordPress menus to your logged in users. In this blog, we will show you how to how to show different WordPress menus to logged in users in WordPress.

Don't Want To Touch Any Code?

Have one of our WordPress Experts add the following code snippets for you. Chill out while we do the hard work.

Get Help
Creating the new WordPress Menus

In WordPress even if your theme has one menu location, you can still create multiple WordPress menus for the same location.

Go to Appearance > Menus, create two menus logged-in and logged-out.

Wordpress Tutorial: Display Different Wordpress Menus to Logged in Users

After creating the menus, add this code in your theme or child theme’s functions.php file or a site-specific plugin:

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' );

That’s all you will see that your logged in visitors will see the logged-in menu and the non-registered or logged out users will see a different menu.

This method allows you to create two different menus for your users so that you can freely update your menus for logged in or logged our users. We hope this blog topic helps you show different menus to logged in users in your WordPress site. For questions please leave a comment below.

Need Help with your Website?

Our Experts can handle any customization or developement at a reasonable price.

Get a Quote

Looking for more?

Here are some other articles that we think you will be interested in!

The time has come and we are eager to announce the long-awaited launch of WP Codeus 1.0! Not only that, but we are also ...