ButlerBlog

chad butler's weblog

  • About
  • Blog
  • WordPress Plugins
  • Contact
Home / Web / WordPress / Show menu based on WordPress login status

Show menu based on WordPress login status

By Chad Butler 59 Comments

In this example, I will show you how to display a different menu for users based on their login status for the WordPress TwentyTen theme.  This process can be adapted to any theme (and using the same principles, could be adapted to use anywhere on your WP site).

Some Prerequisites

This is primarily for those using WP-Members who have asked about showing different menu items based on a user’s login status; but the method described is not limited to use with the plug-in.  This will work with any WordPress installation.

This post assumes that the reader is already familiar with creating menus through the WordPress admin panel.  If not, you can familiarize yourself with this process via the WordPress Codex.

It is VERY important to note that you should not make the discussed edits to TwentyTen directly.  You should be using a child theme for any changes, otherwise, when you upgrade WordPress or TwentyTen, your changes will be overwritten.  A tutorial on creating child themes is not the purpose of this post.  If you are not familiar with this process, begin with the WordPress Codex description of Child Themes.

The Process

First, create two menus.  This is done in your WP admin panel under Appearance > Menus.  For this example, I created on called “logged-in” and one called “logged-out”.  It should be intuitive which is which.

For the “logged-in” menu, add the pages and content you want in the menu for users who are logged in.  For the “logged-out” menu, put in the content to display if the user is not logged in.

To implement these menus, you will make a slight change to the header.php file for the TwentyTen theme.  Look for the following line in this file:

<?php wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary' ) ); ?>

Replace that line with the following:

<?php
if( is_user_logged_in() ) {
	$menu = 'logged-in';
} else {
	$menu = 'logged-out';
}

wp_nav_menu( array( 'menu' => $menu, 'container_class' => 'menu-header', 'theme_location' => 'primary' ) );
?>

Basically, we are just adding another parameter for wp_nav_menu to determine which menu to load.  We are using a variable $menu that will provide the menu name depending on the user’s login status.

It’s that simple.

For a related discussion on how to display different elements in the Loop area of your theme, see this post: Blocking Content in a Custom Template.

Enjoyed this article?

Don't miss a single post. Subscribe to our RSS feed!

  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on X (Opens in new window) X
  • Click to email a link to a friend (Opens in new window) Email
  • Click to print (Opens in new window) Print
  • More
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to share on Tumblr (Opens in new window) Tumblr
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Pinterest (Opens in new window) Pinterest

Filed Under: WordPress, WP-Members Tagged With: development, tips, tutorials, WordPress, WP-Members

About Chad Butler

Chad Butler is a freelance writer and web developer. He has developed several popular WordPress plugins and has written for forbes.com, sfomag.com, and investopedia.com. He also runs a small organic farm in east Georgia.

Join Us!

I will never share your information. No spam. No junk. No kidding. Unsubscribe anytime.

Recent Posts:

  • The High Price of Free Plugins
  • YouTube Success: Key Tips for Enhancing Video Optimization and Visibility
  • Mobile App vs. Mobile Website Ideal Choice for your Business
  • Top Strategies to Boost Your Brand’s Visibility and Impact
  • Advanced Blogging Strategies: Using Analytics, A/B Testing, and Conversion Optimization Techniques to Grow Your Audience
  • Unlock Real-Time Process Insights to Save Time and Money
  • How Writers Can Attract More Audience Attention
  • Dress for Success – Even at Home
  • Mastering the Art of Crafting SMART Marketing Goals
  • Rediscover Your Brand Story: 7 Tips for Refreshing Your Company Identity

Archives

  • About
  • Blog
  • Archive
  • Contact

Site powered by WordPress, running on the Genesis Framework from StudioPress.

Unless otherwise noted, content on this site is © 2006-2025 ButlerBlog and may not be reproduced without express written permission from the author.

Some content may include affiliate links for which this site receives a small commission.