Sometime we want to hide some menu item for site visitors so with the help of these wordpress function we can do that easily.
1st Way..
First edit your theme functions.php file and Register Navigation menu by using register_nav_menus() function there, like this..
<?php function register_nst_nav() {
register_nav_menus(
array(
'logged-in' => __( 'Logged in' ),
'logged-out' => __( 'Logged out' )
)
);
}
add_action( 'init', 'register_nst_nav' ); ?>
Than you can add the below one code to your header.php or footer.php file..
<?php if (is_user_logged_in()) {
wp_nav_menu( array( 'theme_location' => 'logged-in' ) );
} else {
wp_nav_menu( array( 'theme_location' => 'logged-out' ) );
} ?>
Go to Appearance > Menus page and then add menu item to both logged in and logged out Menus..Like this
Now hit Save Menu button there to save menus and after that you can see the output on the header or footer section of the site ! 🙂
2nd way to do this is by using plugin..
By using this https://wordpress.org/plugins/if-menu/ plugin . you can show and hide menu item as per user role, logged in etc.. its a very simple way to do this.