Changing WordPress PHP to Show Different Menu to Logged In Users

I’m building a membership website on WordPress and would like to show a different navigation menu to logged in users.

Here is the current PHP code that displays the menu :

Read More
                <?php /* Our navigation menu. */ ?>
<?php if ( isset ($options['admired_remove_superfish']) &&  ($options['admired_remove_superfish']!="") )
                    wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary' ) );
                else
                    wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary', 'menu_class' => 'sf-menu','fallback_cb' => 'admired_page_menu'  ) );?>

Here’s the PHP code that needs to replace that code :

<?php
    if ( wp_emember_is_member_logged_in() ) {
    wp_nav_menu( array( 'menu' => 'logged-in-members' ) );
  } else {
    wp_nav_menu( array( 'menu' => 'normal-visitor-menu' ) );
  }
?>

If I just replace the old code, with the newer code it will work, but the formatting is off. I need the Superfish part in the current code, but I’m not sure how to make it work in PHP.

I know this may be a little confusing, but I would appreciate any help. Thanks!

P.S. This is a tutorial from the plugin’s site. I’ve been following it, but I somehow need to keep the Superfish in there. I’m sure not sure how to do it.

http://www.tipsandtricks-hq.com/wordpress-membership/show-different-navigation-menu-to-your-members-and-non-members-551

Related posts

Leave a Reply

2 comments

  1. The 'menu_class' => 'sf-menu' will add the sf-menu class for the menu (<ul class="sf-menu">) and super fish plugin will use this class to identify the menu and style will be applied which has been declared in the super fish plugin’s css

    <?php
        if ( wp_emember_is_member_logged_in() ) {
            wp_nav_menu( array( 'menu' => 'logged-in-members', 'menu_class' => 'sf-menu' ) );
        } else {
            wp_nav_menu( array( 'menu' => 'normal-visitor-menu', 'menu_class' => 'sf-menu' ) );
        }
    ?>
    

    For more see this.

  2. Considering the code above, the only thing that is changing is the actual location of the menu. The (existing) code is showing that you want the menu that’s in 'theme_location' => 'primary' where, as you have a hardcoded menu you want to use, and you’re selecting it with 'menu' => 'loggged-in-members' The finished result will be…

    <?php
        if ( wp_emember_is_member_logged_in() ) {
           wp_nav_menu( 
               array( 
                   'container_class' => 'menu-header', 
                   'menu' => 'logged-in-members', 
                   'menu_class' => 'sf-menu',
                   'fallback_cb' => 'admired_page_menu' 
               ) 
           );
        } else {
            wp_nav_menu( array( 'menu' => 'normal-visitor-menu' ) );
        }
    

    ?>