If User Logged in.. Show and hide Menu in wordpress !

Hide or show menu in wp

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
 
wp hide show menu

 
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.

If this help you then.. Can you buy a Cup of Coffee for me by nst webcreation paypal--OR-- nst webcreation blog coffee cup

Published by

NST

Myself Narender Singh Thakur ( NST ) and i share my Experience/Knowledge and Tricks for folks and beginners to solve their issues while making websites through this Planet.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Click to Chat