If the login user and the non login browser display different menus, the following code can be used:
the login user displays different WordPress menus
add the following code to the current topic function template functions.php Medium:
if( is_user_logged_in() ) { $args['menu'] = 'logged-in'; } else { $args['menu'] = 'logged-out'; } return $args; } add_filter( 'wp_nav_menu_args', 'wpc_wp_nav_menu_args' );
After that, two new menus, logged in and logged out, are created respectively for the menus displayed by the login and ordinary visitors.
if the topic has multiple menus, you can display different menus in the specified menu position through the following code:
function wpc_wp_nav_menu_args( $args = '' ) { if( is_user_logged_in()) { if( 'top-navigation' == $args['theme_location'] ) { // Change top-navigation to theme specific name $args['menu'] = 'logged-in'; } } else { if( 'top-navigation' == $args['theme_location'] ) { // Change top-navigation to theme specific name $args['menu'] = 'logged-out'; } } return $args; } add_filter( 'wp_nav_menu_args', 'wpc_wp_nav_menu_args' );
You can also use the above method to let different user roles display different menu contents.
original code: https://wpcodeus.com/display-different-wordpress-menu-to-logged-in-users/