Different Menu for Logged-In Visitors
Shows another navigation menu to logged-in users in the same theme location, for example with "My account" and "Log out" instead of "Sign up".
Opens WPIDE on
Code
// Theme location to swap and the menu to show to logged-in users.
$wpide_member_menu_location = 'primary';
$wpide_member_menu = 'Members Menu';
add_filter( 'wp_nav_menu_args', function ( $args ) use ( $wpide_member_menu_location, $wpide_member_menu ) {
if ( ! is_user_logged_in() || empty( $args['theme_location'] ) || $wpide_member_menu_location !== $args['theme_location'] ) {
return $args;
}
if ( wp_get_nav_menu_object( $wpide_member_menu ) ) {
$args['menu'] = $wpide_member_menu;
}
return $args;
} );
Notes
Create the menu under Appearance > Menus and put its name or slug in $wpide_member_menu. Works with classic themes.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.