• I’m building a member only site and I want to only have member pages navigation links in the primary nav visible after the user has logged in. Right now I have all the page links shown in the primary nav which is a problem. I’m using the Responsive Theme 1.4.9 and I see that there so some changes need to be done in the functions.php and header.php file
    I’ll list my current code in those two files below, please help with the php code snippet to replace the default theme code as you did on similar post…

    https://www.ads-software.com/support/topic/want-primary-navigation-to-change-on-members-only-pages?replies=23#post-2822856

    functions.php code looks like this

    register_nav_menus(array(
    'top-menu' => __('Top Menu', 'responsive'),
    'header-menu' => __('Header Menu', 'responsive'),
    'sub-header-menu' => __('Sub-Header Menu', 'responsive'),
    'footer-menu' => __('Footer Menu', 'responsive')
    )
    );

    header.php code looks like this

    <?php wp_nav_menu(array(
    				    'container'       => '',
    					'menu_class'      => 'top-menu',
    					'theme_location'  => 'top-menu')
    					);
    				?>
            <?php } ?>

    Please help me

Viewing 15 replies - 1 through 15 (of 20 total)
  • I don’t think you need any changes to functions.php. Just create a new menu in Admin->Appearance->Menus. Assuming you call it ‘Members’, your header.php code would be like this:

    <?php if ( is_user_logged_in() ) {
       wp_nav_menu(array( 'container' => '',
          'menu_class' => 'member-menu',
          'menu'  => 'Members')
       );
    } else {
       wp_nav_menu(array( 'container' => '',
          'menu_class' => 'top-menu',
          'theme_location'  => 'top-menu')
       );
    }
    ?>
    Thread Starter qmic76

    (@qmic76)

    Thanks for your help but I’m still a little confused.

    I’ve implemented the code to header.php. But I’m not sure what you mean about creating a “Member” menu. I go to appearance/menus/ then I created a menu called “Members” but what pages should I include the ‘members’ menu?

    The first time I created the ‘members’ menu after you suggested it, I only included the pages that should be seen by members once they are logged in (members and projects). When I reloaded and logged out to check it, it only shows “members and projects” in the primary nav even though I’m logged out when it should be showing ‘about and register’ and only show ‘member and projects’ after logging in. I’m confused, am I not making the menu correctly or should there more code to defect login status in header.php or even functions.php (I did not change anything in functions.php based on your first response). As of right now its not defecting the login status change to switch between the 2 navigation displays. Please help

    The code I showed should show one menu when logged in and another when not logged in. Don’t know why it isn’t doing that.

    Each menu should include everything that you want to show for that menu, not just parts that should be added to the other menu.
    EDIT: Here is where I got that bit of code:

    https://desizntech.info/2011/02/wordpress-hacks-for-members-only-website/

    I changed it a bit so you do not need to modify functions.php. I used the ‘menu’ parameter instead of the ‘theme_location’ parameter.

    Thread Starter qmic76

    (@qmic76)

    ok this is the complete header div code below you gave me nested, is there anything else I should change or take out?

    <div id="header">
    
            <?php if (has_nav_menu('top-menu', 'responsive')) { ?>
    
    	        <?php if ( is_user_logged_in() ) {
      				 wp_nav_menu(array( 'container' => '',
         				 'menu_class' => 'member-menu',
         				 'menu'  => 'Members')
       				);
    				} else {
      				 wp_nav_menu(array( 'container' => '',
         				 'menu_class' => 'top-menu',
          				'theme_location'  => 'top-menu')
       				);
    			}
    		?>
    
            <?php } ?>

    Then I made two menus named…
    “top-menu” that has “about and register” shown for nav links
    “members” that has “members and projects” shown for nav links
    Both of these menus I dragged/clicked the corresponding pages then I saved the menus to be in the header region of the page. I then created a “dummy user” to sign up on a different browser to be on the safe side.

    On first load/display..about and register is shown in primary nav, then when logging in with the “dummy user” login, it still displays “about and register” not switching to the members menu..what I’m missing or doing wrong? When I first tried your suggestion I only created the one ‘members’ menu and clicked on ‘member and project’ pages to be linked to that menu and that didn’t work so I tried to create two menus and no luck..

    This is just a guess, but try taking out the nesting.

    Tami

    (@tammy-m-rogers)

    I have a related but not exactly the same question. I have a genesis child themed site that has both English and French pages. I would like an English menu to be in the Primary Menu location when on English pages and French on the French. Under “menus” I can only chose one menu to appear (obviously) but is it possible to have 2 registered menus to the same location and have them page specific?

    You will have better luck if you start your own thread rather than adding a different question to an old thread.

    You are missing the Theme Location for the members, add a new location and create a members menu assign the menu to the new theme location!

    In functions.php add the new location!

    'members-menu' => __('Members Menu', 'responsive'),

    In header.php based on twenty eleven child theme, make the location conditional!
    UNTESTED:

    <?php $location = is_user_logged_in() ? 'members-menu' : 'top-menu'; ?>
    <?php wp_nav_menu( array( 'theme_location' => $location ) ); ?>

    HTH

    David

    EDIT: GRRRRR! another old topic posted an answer to, at least this one is not 9 months old!

    @digital Raindrops, there is no need for another Theme Location. If you look back to the code I first posted, it uses the ‘menu’ argument rather than the ‘theme_location’. That code was tested and works.

    Hi vtxyzzy,
    More than one way to skin a cat, I thought it was a new and active topic I was answering with another solution, but it was historic ;(

    Theme Location is just another option, and the code is very tidy as the menu can be called whatever the website admin wants, I never hard code values myself, menu => ‘members’ is only ok when the admin knows what to call the menu, however if the website admin changes, or the the menu was deleted the members menu feature could then be lost!

    To me the ‘Theme Location’ solution is transportable across themes, if the theme location menu does not exists it will fall through to get_pages, it might help others looking for the same solution, this is not a critique of your solution, just my own opinion!

    David

    Thread Starter qmic76

    (@qmic76)

    vtxyzzy,

    I tried taking out the nesting and I also added echo statements to see if the function is even being called and none of the echo statements would show, letting me know that the function is not being called at all. Are you sure I do not need to add any code to functions.php. I’ve already created the members menu which includes the links I want to show when users are logged in.

    Heres what my code looks like now..

    <?php if (has_nav_menu('top-menu', 'responsive')) { ; ?>
    
    	        <?php
    			$result = is_user_logged_in();
    			echo "RESULT IS $result<br />";
    
    			if ( is_user_logged_in() ) {
    				echo "I AM LOGGED IN";
      				 wp_nav_menu(array( 'container' => '',
         				 'menu_class' => 'member-menu',
         				 'menu'  => 'Members')
       				);
    				} else {
    				echo "NOT LOGGED IN";
      				 wp_nav_menu(array( 'container' => '',
         				 'menu_class' => 'top-menu',
          				'theme_location'  => 'top-menu')
       				);
    			}
    		?>

    I even created a top-menu along with member menu to see if that would work but it didn’t so I went back just having the one members menu.

    Do you see your message “RESULT IS xx” ?

    If not then the first if test is returning false. Try changing it to this (just temporarily for debugging):

    <?php if ( true || has_nav_menu('top-menu', 'responsive') ) { ; ?>
    Thread Starter qmic76

    (@qmic76)

    Great i’m getting somewhere using the amended debugging code you provided. Now I can see the “RESULT IS..(not logged or logged in) based on log in status, but now it also created a duplicate menu above my main navigation in the (top-menu) space of the screen (upper right), which I don’t want. The main navigation looks the same still all the links shown regardless of log in state, but when I log in or out the duplicate “top nav” it made does show only “member and project” in the menu when the user is logged in, I just want this to happen to my primary nav in the header…if your confused visit my site at mks76.com/wp/

    NEVER EVER post a username and password on a public forum.

    REMOVE IT NOW!!

    Thread Starter qmic76

    (@qmic76)

    Ok I remove it, It wasn’t my admin account pass/loggin anyway. I just created that for you to see what I’m talking about if I didn’t explain the issue properly, I’m sorry. Any insight?

    Right now i’m trying to remove the top-menu it created and have the function effect the member’s menu so any help with that would be great thanks

Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘Want Primary Navigation to Change on Registered user Only Pages’ is closed to new replies.