0

I'm trying to show one menu based on whether or not the user is logged in. It's straight forward enough but when I change to my code I have no styles or icons like the original - see code below

ORIGINAL CODE (Menu looks fine)

<div id="main-menu">
<?php wp_nav_menu(array('theme_location' => 'primary', 'menu_id' => 'sf-menu',         
'walker' => new header_one_uou_nav_menu) );?>
</div>

MY CODE (Will show correct menu based on login but with no icons and formatting)

<div id="main-menu">
<?php 

if( is_user_logged_in() ) {
$menu = 'menu_LI';
} else {
$menu = 'sf-menu';
}

wp_nav_menu( array( 'menu' => $menu, 'container_class' => 'menu-header',
'theme_location' => 'primary', 'menu_id' ) );

?>


</div>

Link to menu for reference of what it is supposed to look like

Any suggestions would be appreciated

3

Ok, there are some pretty obvious differences between the original and your code, like:

  • the use of a walker
    • this is most certainly needed for the fancy styling
  • the lost and empty menu_id parameter
    • depending on the according CSS this might be needed too
  • the use of the menu parameter
    • ok, to switch the menu displayed we need this
  • addition of of a container_class
    • could possibly influence how the menu is displayed, depends on the CSS

That said, try this:

if( is_user_logged_in() ) {
    $menu = 'menu_LI';
} else {
    $menu = 'sf-menu';
}

wp_nav_menu(
    array(
        'menu'            => $menu,
        'container_class' => 'menu-header',
        'theme_location'  => 'primary',
        'menu_id'         => 'sf-menu',
        'walker'          => new header_one_uou_nav_menu
    )
);

Furthermore you might have to adjust or play around with the parameters to get this working perfectly. Take above list as starting point and you might want to read the wp_nav_menu() again and possibly take a look at how the Walker thing works.

  • Ok thanks man - For now i have only one menu element that i wanted to hide so i have created a new page template for that page and added an if statement at the top of the page and a die statement as the else with a login message requiring login. Will try your suggestion and once i have it tuned up i will post back. thanks again – anthonytherockjohnson Sep 19 '14 at 11:25
  • My pleasure. Sure, report back the progress, it's always helpful. @anthonytherockjohnson – Nicolai Sep 19 '14 at 11:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.