Below is the code to show a different navigation menu to logged-in users in WordPress.
Alternatively, if you prefer to hide custom menu items based on user roles, you can download and install Nav Menu Roles from the WordPress Plugin Repository.
Below is the code to show a different navigation menu to logged-in users in WordPress.
<?php | |
//* Show a different navigation menu to logged-in users in WordPress | |
function prefix_show_different_menu($args = '') { | |
if (is_user_logged_in()) { | |
$args['menu'] = 'logged-in'; // Navigation menu's name when users are logged-in | |
} | |
else { | |
$args['menu'] = 'logged-out'; // Navigation menu's name when users are not logged-in | |
} | |
return $args; | |
} | |
add_filter('wp_nav_menu_args', 'prefix_show_different_menu'); |
Alternatively, if you prefer to hide custom menu items based on user roles, you can download and install Nav Menu Roles from the WordPress Plugin Repository.