How to display different menus for logged-in and logged-out users in WordPress

H

Add the following snippet of code in your theme to the location where you would like the menu’s to be displayed.

<?php
if ( is_user_logged_in() ):
 wp_nav_menu( array( 'menu' => 'Loggedin' ) );
else:
 wp_nav_menu( array( 'theme_location' => 'primary' ) );
endif;
?>

Basically, what the code above does, it checks if the user is logged-in and then displays the LoggedIn menu, you may replace LoggedIn with your menu name.

If the user is not logged-in we display the primary menu.

About the author

Ian Carnaghan

I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment.

About Author

Ian Carnaghan

I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment.

Follow Me