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' );
Was this post helpful?
Let me know if you liked the post. That’s the only way I can improve. 🙂