Something we’ve come across lots of times in WordPress is how to hide a specific menu item in WordPress menus if the user is logged-in, or indeed logged out. A common application for this would be if you have a registration page which you obviously don’t want to continue to show if the user has already registered (they are logged in).
Previously we have delved into the site head and the menu itself to use WordPress Conditional Tags/Statements. So for example:-
<?php if ( is_user_logged_in() ) { echo 'Welcome, registered user!'; } else { echo 'Welcome, visitor!'; } ?>
So in respect of the Nav you could use the following in in header.php (in place of the regular wp_nav_menu), under div access/role
<?php if(is_user_logged_in()){ wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary', 'exclude' => '39' ) ); } else{ wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary' ) ); } ?>
Just add the page id to exclude to the logged in user.
An easier Way!
The above is fine and dandy if you can access your site files and/or are happy to modify the template(s) code, but there is an even easier way and that is via the following plugin:-
The plugin created by Peter Wooster is freely available on the WordPress plugin repository via the link above and this makes removing pages from the WordPress Nav on logged in status an absolute breeze. Indeed it also hides the page content itself as to whether the user is logged in or logged out:-
A very useful plugin!