X

How to Display Custom Menus to Logged-in Users in WordPress

Snippets by IsItWP

Are you building a website that requires users to logged in to access it? Then, you’ll likely need a dynamic navigation menu that displays different menu items to users depending on whether they’re logged in or not. In this article, we’ll show you how to display custom menus to logged in users.

Instructions:

Add this snippet to the template file where you want to display your navigation menu.

<?php
if ( is_user_logged_in() ) {
     wp_nav_menu( array( 'theme_location' => 'logged-in-menu' ) );
} else {
     wp_nav_menu( array( 'theme_location' => 'logged-out-menu' ) );
}
?>

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: Best WordPress Page Builders (Compared).

Comments   Leave a Reply

  1. How do you add this to a theme? The above code shows nothing in the navigation menu

  2. Wordpress Buddypress Different Menu for Logged In and Non-Logged in Users | Archturus Media September 11, 2012 at 5:54 pm

    […] I’ve been in the process of building an online community for the Utah Grotto of the National Speleological Society and ran into a wall when it comes to creating a different menu for logged in and non logged in users. The primary problem was in the fact that several of the buddypress supported themes only support one menu and you need at least two in order for the is_user_logged_in() function to work properly. So here was the solution I came up with after referencing the following sites: http://wpsnipp.com/index.php/theme/display-different-menus-for-logged-in-users/ and http://smartcoderszone.com/2010/07/how-to-add-multiple-menu-in-wordpress/. […]

  3. AWESOME! Thank you a billion times!

    1. Np Erwin, glad that I could help.

  4. Thank you – I’ll give this a try 🙂 

    Just found this site and I think it is going to be invaluable to me.

    Thank you.

    1. Hi Janice glad to hear you like wpsnipp, hope that you enjoy all the snippets.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!