This is searchable archive of our old support forums, which operated from 2012 - 2016. To find out how to get support for your current theme, please visit our support page.

Errors in setting up separate menus for logged in/logged out members

  • Creator
  • #11246
    Joseph Sellers


    I am trying to work out how to have a different menu for logged out users and logged in users.

    This is the functions.php that I have in the child theme.

    This works, nearly but it creates problems whenever a page is saved and users are facing issues when logging in.

    I checked the error log and I think this could be the error that is indicating the problem.

    PHP Warning: Cannot modify header information – headers already sent by (output started at /home/woodwork/public_html/wp-content/themes/jumpstart-stretch/functions.php:62) in /home/woodwork/public_html/wp-includes/pluggable.php on line 875

    Can someone please take a look and tell me what I am doing wrong?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
  • #11259
    Jason Bobich


    This function you’ve declared logged_inout_menu, you forgot to close it. In other words, you’re missing a } at the end, and maybe have confused your braces up earlier in the function.

    Here’s more like how you want to format that section:

    function logged_inout_menu() {
    	do_action( 'themeblvd_header_menu_before' );
    	<a href="#access" class="btn-navbar">
    		<?php echo apply_filters( 'themeblvd_btn_navbar_text', '<i class="icon-reorder"></i>' ); ?>
    	<nav id="access" role="navigation">
    		<div class="access-inner">
    			<div class="access-content clearfix">
    				if( is_user_logged_in() ){
    					wp_nav_menu( apply_filters( 'themeblvd_primary_menu_args', array( 'menu_id' => 'primary-menu', 'menu_class' => 'sf-menu','container' => '', 'theme_location' => 'logged-in', 'fallback_cb' => 'themeblvd_primary_menu_fallback' ) ) );
    				} else {
    					wp_nav_menu( apply_filters( 'themeblvd_primary_menu_args', array( 'menu_id' => 'primary-menu', 'menu_class' => 'sf-menu','container' => '', 'theme_location' => 'logged-in', 'fallback_cb' => 'themeblvd_primary_menu_fallback' ) ) );
    			</div><!-- .access-content (end) -->
    		</div><!-- .access-inner (end) -->
    	</nav><!-- #access (end) -->
    	do_action( 'themeblvd_header_menu_after' );
    remove_action( 'themeblvd_header_menu', 'themeblvd_header_menu_default' );
    add_action( 'themeblvd_header_menu', 'logged_inout_menu' );

    And notice how there’s a filter “themeblvd_primary_menu_args” in there? You could actually do this instead of the above, which might be a bit cleaner and not make you mess with around with other stuff that doesn’t correspond to what you’re editing (i.e the menu theme_location).

    function my_primary_menu_args( $args ) {
    	if( is_user_logged_in() ) {
    		$args['theme_location'] = 'logged-in';
    	} else {
    		$args['theme_location'] = 'logged-out';
    	return $args;
    add_filter('themeblvd_primary_menu_args', 'my_primary_menu_args');

    And where you’re adding your theme menu locations, this is another good example of where you should be utilizing the filter. Only use pluggable functions as a last resort. So, here’s how you could do essentially the same thing with a filter there as you’re accomplishing now with the pluggable function:

    function my_nav_menus( $menus ) {
    	$menus = array(
    		'logged-in'		=> __( 'Logged In Menu', 'themeblvd' ),
    		'logged-out'	=> __( 'Logged Out Menu', 'themeblvd' ),
    		'footer'		=> __( 'Footer Navigation', 'themeblvd' )
    	return $menus;
    add_filter( 'themeblvd_nav_menus', 'my_nav_menus' );

    More about how filters work:

    Also, here’s another big thing I’m noticing throughout your file, which is actually the direct cause for the error you originally cited. With PHP, you can’t start the output buffer early, before the HTML document is outputted on the page. You’re doing this accidentally with all the places in your functions.php where you’re opening and closing PHP outside of your functions.

    So, for example say you had this:

    function foo() {
    	// do something ...
    function bar() {
    	// do something ...

    Where PHP is being closed and opened again randomly in the middle, you’re actually outputting blank space there. This type of thing is what will give you a “Cannot modify header information” warning or error.

    Joseph Sellers

    That is fantastic. Thank you so much for your help.



Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.