Hide One or More Nav Menu Item from Logged out user
-
I want to hide an item from my Menu, if a user is logged out.
So my Menu has | Home, Listings, Store Manager, About | — as the Menu Items.
I will like “Store Manager” to be hidden when the user is logged out, and made visible on the Menu when the user is logged in.
Currently, I believe that the below code will achieve this for me.
But it relies on me creating and using Two(2) separate Menus.
To save myself from duplication, I would like to only have to manage One Nav Menu.
Here’s the Code I presently have:
function my_wp_nav_menu_args( $args = '' ) { if ( is_user_logged_in() ) { $args['menu2'] = 'logged-in'; } else { $args['menu'] = 'logged-out'; } return $args; } add_filter( 'wp_nav_menu_args', 'my_wp_nav_menu_args' );
Is it possible to hide just one item for a logged out user, rather than doing it the way I am aimed at going— where I have Two(2) Nav Menus, and would actually want to have just One(1) Nav Menu?
2.) It was suggested somewhere that CSS can do it.
But I don’t like the idea of just hiding Menu items with CSS as they would still be visible using the code inspector on the page.
I am looking for a more secure way of removing menu items, without being able to still see them with the Page inspector on the frontend.
Anyone with a better code that can help me achieve this?
Regards.
- The topic ‘Hide One or More Nav Menu Item from Logged out user’ is closed to new replies.