Hiding Nav Menus from Logged Out Users
-
Hey,
I’ve been trying to modify my theme to display different menus to users logged in. I’ve created two menus in wordpress called logged-in and logged-out and was trying to apply a condition to display the correct menu. I’ve tried various plug-ins, which do change the menus but they don’t seem to be detecting if a user is logged in or not.
I’ve added the following code to functions.php.
if( is_user_logged_in() ) { $args['menu'] = 'logged-in'; } else { $args['menu'] = 'logged-out'; } return $args; } add_filter( 'wp_nav_menu_args', 'my_wp_nav_menu_args' );
And found references to nav menus in the following locations.
Functions.php
register_nav_menus( array( 'primary' => __( 'Primary menu', 'magnis' ), 'secondary' => __( 'Footer menu','magnis' ), ) );
Header.php
<!-- site desktop menu start //--> <nav class="site-desktop-menu"> <?php $primarymenu = array( 'theme_location' => 'primary', 'menu' => '', 'container' => '', 'container_class' => '', 'container_id' => '', 'menu_class' => '', 'menu_id' => '', 'echo' => true, 'fallback_cb' => 'wp_page_menu', 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '', 'items_wrap' => '<ul>%3$s</ul>', 'depth' => 0, 'walker' => '' ); if ( has_nav_menu( 'primary' ) ) { wp_nav_menu( $primarymenu ); } ?> </nav>
Any ideas how to update them properly. Thanks for your help.
D
- The topic ‘Hiding Nav Menus from Logged Out Users’ is closed to new replies.