How to Show Different Menus to Logged in Users in WordPress

204

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.

Creating Multiple Menus in WordPress

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

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

Create two different menus for logged in and logged out users

After creating the menus, add this code in your 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 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 out users. There are other ways to do the same thing. For example, if you just want to add login and logout links to your navigation menu then you should add custom menu items in WordPress navigation menu.

We hope this article helped you show different menus to logged in users in your WordPress site. For questions and feedback please leave a comment below.

Social Media Auto Publish Powered By : XYZScripts.com