wp-content » themes » functions.php » Show different menus to logged-in users in WordPress

Show different menus to logged-in users in WordPress

Here is a small snippet that you can add to your functions.php file to show different menus to logged-in users in WordPress. In this example 5 is the menu ID of the menu shown to logged-in users and 6 is the ID for the menu shown to guests. So, create two menus and copy their ID’s then change the values in this snippet:

// Show different menu to logged in users

function md_nav_menu_args( $args = '' ) {
  if( is_user_logged_in() ) {
  // for users
  $args['menu'] = 5;
   
  } else {
  // for guests
  $args['menu'] = 6;
  }
  return $args;
  }
  add_filter( 'wp_nav_menu_args', 'md_nav_menu_args' );
See also  WooCommerce 📱 phone number verification (+381)

Was this post helpful?

Leave a Comment

I enjoy constructive responses and professional comments to my posts, and invite anyone to comment or link to my site.

Recommended