We’ve blogged previously about using the Nav Menu Roles plugin along with the PMPro Roles add on to create conditional menu items. Here’s another tutorial that demonstrates two options for conditional navigations menus: editing your theme or our super cool new Nav Menus Add On.


Option 1: Edit Your Theme

This demo is particularly useful if you’re a theme author looking to build member menus directly into your theme.

Step 1: Register the Members Navigation Menu

In your theme’s functions.php file, add the following code:

function mytheme_register_my_members_menu() {
	register_nav_menu( 'primary-members', __( 'Primary Menu - Members', 'theme-slug' ) );
	register_nav_menu( 'primary-nonmembers', __( 'Primary Menu - Non-Members', 'theme-slug' ) );
}
add_action( 'after_setup_theme', 'mytheme_register_my_members_menu' );

Duplicate the ‘register_nav_menu’ line for every new menu needed, such as a conditional footer menu, or for each membership level on your site to create a unique menu by level ID.


Step 2: Edit Your Theme’s header.php File

The code below should replace your theme’s ‘wp_nav_menu’ code. If there are special attributes declared in your theme’s existing ‘wp_nav_menu’ code, you should mirror those for the new member/non-member menus. See this guide from the WordPress Codex for help.

//is there a user to check?
if ( is_user_logged_in() && function_exists('pmpro_hasMembershipLevel'))
{
	//check level
	if(pmpro_hasMembershipLevel())
		wp_nav_menu( array( 'theme_location' => 'primary-members' ) );
	else
		wp_nav_menu( array( 'theme_location' => 'primary-nonmembers' ) );
}
else
{
	wp_nav_menu( array( 'theme_location' => 'primary-nonmembers' ) );
}

Step 3: Create the Members and Non-Members Custom Menus

pmpro-members-menu

  1. In the WordPress admin go to Appearance > Menus.
  2. Click the “create a new menu” link to add a new “Members” menu.
  3. Add menu items to this menu, check the “Primary Menu – Members” Theme Location under “Menu Settings”, and save the menu.
  4. Click the “create a new menu” link to add a new “Non Members” menu.
  5. Add menu items to this menu, check the “Primary Menu – Non-Members” Theme Location under “Menu Settings”, and save the menu.

You’re Done!

From here you should navigate to your site both as a member and a non-member to verify that everything is working as intended.


Option 2: Use the Nav Menus Add On

We just released a new add on that does all of this for you. The Nav Menus Add On creates member navigation menus and swaps your theme’s navigation based on a user’s Membership Level.

This plugin duplicates all wp_nav_menus defined by your theme and creates a members version. Customize menus even further by optionally creating a level-specific navigation menu. This can be set on the Edit Membership Level screen under the “Navigation Menu” section.

View and Download the Add On


Comments (6)

Author’s gravatar

Hi Kim,

I am a bit confused by this. I like the idea of setting up two menus for members and non-members (actually the first site that I’m doing with PM Pro needs 3 menus for 3 different levels), but my theme, Headway, only allows 1 navigation menu per page, so the pages that both members and non-members can access are beyond my logic. The answer is likely very simple and I just can’t see it right now; please advise.

Thanks,

Mike

Reply
Author’s gravatar

Hi, Mike. I think if you use the PMPro Nav Menus add on, you’ll be able to set which menu is used for which level and to your theme it will look like one menu basically. Open a thread on our member forums with as much info as possible about your menus and what you need, and I’ll try to whip up instructions specifically to work with Headway.

Reply
Author’s gravatar

Hi Jason. I had a parallel ticket out to Headway, and they pointed out that after menu creation, the switch between menus based on user level may be accomplished via CSS. Unfortunately, PMPro Nav Menus conflicted with my first effort at augmented menus: Nav Menu Roles, even after I changed the PMPro levels to roles using PMPro Roles plugin. But Jamie is working through the CSS setup on my website’s backend; and if it works, I could share the solution with you. I would rather not share the details of my menus in a public forum. I do not mind making you admin on the site, however, if you would like to observe the solution directly when it’s done, or solve it directly if not; and then share it with the public after.

Author’s gravatar

Aaah no need to hold back a solution from everyone else; others will be able to receive help from this if I share publicly most likely. Public ask coming forthwith.

Author’s gravatar

Hi,
is it correct that I can only create a non-member menu with the first option, not with the Nav Menus Add On? Or can I also modify the Nav Menus Add On files in order to achieve this?
I have a public menu (working fine) a members menu (working fine) a member level menu for only one kind of membership (working fine) now I would like to create a non-members menu for logged in people who don’t have a membership, and can’t find an option for this.

Best,
Simon

Reply
Author’s gravatar

This add on does not have a feature like this at this time. The non-member (logged in) would see the same menu as the logged out “visitor”. I’ll put a feature request in for this add on but can’t promise a turnaround. If you are a support member and post a topic on the members forum we would be able to get you the needed update for your project.

Reply

Leave a Reply

Your email address will not be published. Required fields are marked *