Jump to content
Sign in to follow this  
ksnyde

Hooking into the Primary Nav

Recommended Posts

ksnyde

I need to change my menu between when I'm logged in and when not. I've done this quite easily using more basic themes than PageLines but it's more complicated in the PageLines universe. I'm happy to do it whatever way is most conducive to PageLines but here's my approach so far. First step: create two menu areas in WP by adding this into my child theme's functions.php file:

	register_nav_menus( array(
	  'logged-in'  => __( 'Logged-in Menu Area',  'lifegadget-pagelines' ),
	  'visitor' => __( 'Visitor Menu Area', 'lifegadget-pagelines' ),
	));
	
This results in this: screenshot. Second step: toggle the wp_nav_menu based on logged in status
	if (is_user_logged_in()){
	  wp_nav_menu( array(
	    'menu'            => 'Logged In Menu',
	    'container_class' => 'logged-in-menu',
	    'theme_location'  => 'logged-in'
	  ));
	} else {
	  wp_nav_menu( array(
	    'menu'            => 'Visitor Menu',
	    'container_class' => 'visitor-menu',
	    'theme_location'  => 'visitor'
	  ));
	};
	
Conclusion: Sadly this doesn't work. The first thing you notice is that the menu choices for the visitor menu appear awkwardly in the upper-left hand of the admin menu (and non-admin menu too). In the non-admin screens the main nav doesn't change at all and some pages now don't load including an error message stating:
	Warning: Cannot modify header information - headers already sent by (output started at /[PATH]/wp-includes/nav-menu-template.php:235)
	

Please help and if I could I would like to suggest that this be made more "out of the box" feature in the future as it's a very common request for blog+ and application sites.

Share this post


Link to post
Share on other sites
Rob
Ken, I'll happily suggest and highly recommend your suggestion. Unfortunately, I'm not sure of the solution and will ask one of our developers to check into it. May I ask you to file a Bug report for PageLines Framework at http://www.pagelines.com/tracking ? Normally, I'd do this but it would keep you more directly in the loop if you submit it directly.

Former PageLines Moderator, Food Expert and Raconteur

Share this post


Link to post
Share on other sites
ksnyde
@rangealone, I've put in the request. How long do these things take? I have an investor pitch coming up and so I need to know if this will be given attention in time for this or I need to build some "smoke and mirrors" in the mean time.

Share this post


Link to post
Share on other sites
Simon
Where are you adding your 'toggle menu' code?

Share this post


Link to post
Share on other sites
Rob
Ken, it took exactly 21 minutes to get attention. Not bad! Faster than I get attention sometimes.

Former PageLines Moderator, Food Expert and Raconteur

Share this post


Link to post
Share on other sites
ksnyde
@simon, I'm adding it in the functions.php file in my child theme.

Share this post


Link to post
Share on other sites
Simon
you have to put your code in a wordpress action, so it gets executed at the right spot, otherwise it will just be executed first, thats why its breaking your page.

Share this post


Link to post
Share on other sites
ksnyde
I have taken Simon's approach suggested on the defect tracker ... - created a new section in my child theme - the new theme is just a fork of the default "nav" section but it has conditional logic for logged-in or not This works exactly as I'd like it. Happy to share the code if you wanted to incorporate into a future release of Pagelines (it would be a really good "out of the box" feature).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

×