Tagged: 

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #351769

    Hi there,
    I want to display two different menus, depending on whether a user is logged in or logged out. For this I use this code:

    function my_wp_nav_menu_args( $args = '' ) {
     if( is_user_logged_in() && $args['theme_location'] == 'avia' ) {
      $args['menu'] = 'Main-Menu-logged-in';
    } else {
      $args['menu'] = 'Main-Menu';
     }
     return $args;
     }
    add_filter( 'wp_nav_menu_args', 'my_wp_nav_menu_args' ); 

    However, all menus are influenced by this. What should I change so that only the Main Menu varies?
    Thank you and
    many greetings
    Andreas

    #352066

    Hi andrassberlin!

    I tried your code on my XAMPP setup and it seems to be working fine. When I’m logged in only the main menu gets changed and the footer menu stays the same.

    Did you try clearing your browser cache?

    Cheers!
    Elliott

    • This reply was modified 9 years, 4 months ago by Elliott.
    #358572
    This reply has been marked as private.
    #359330

    Hi!

    It seems to be working fine. The only one being changed is your main menu. You currently have it set to display a menu called “Main-menu-logged-in” when your logged in but you have not created a menu with that name yet.

    Regards,
    Elliott

    #359465

    Hey Elliott,
    and thanks for your help!
    in the meantime I have the Main Menu (Main Menu-logged-in) deleted because the menu-chance did not work. I have it rebuilt now. After login, the “Main Menu-logged-in” is displayed correctly. Instead of the other menus (top menu, etc.) always the Main Menu-logged-out is displayed. Unfortunately, this is wrong. Do you have another idea?
    Very many thanks and best regards
    Andreas

    #359868

    Hey!

    I see what you mean now. Not sure why it’s not working for you.

    Try adding it to the bottom of the functions.php file of the parent theme and then activate the parent theme to see what happens. Also be sure to deactivate all plugins while testing.

    I tried the exact names and code in my XAMPP setup so there shouldn’t be anything wrong with the code.

    Cheers!
    Elliott

    • This reply was modified 9 years, 4 months ago by Elliott.
    #359982

    Hi Elliott,
    I followed your advice. Also in the parent theme, the error occurs. Even if I have all the plugins deactivated.I have no idea unfortunately. Should I reinstall enfold / wordpress? I have an alternative option to fix it?
    Thank you.
    Greetings
    Andreas

    #360070

    Hi Elliott – me again ;-)
    Now, I did a totally new installation of wrdpress and enold-theme. Therefore I used the files I bought from you. After this I installed a child theme, downloaded from your site. Then, I constructed two new menus: 1. Main-Menu-logged-out and 2. Main-Menu-logged-in. In the functions.php of the child theme I wrote this correct function:

    function my_wp_nav_menu_args( $args = '' ) {
     if( is_user_logged_in() && $args['theme_location'] == 'avia' ) {
      $args['menu'] = 'Main-Menu-logged-in';
    } else {
      $args['menu'] = 'Main-Menu-logged-out';
     }
     return $args;
     }
    add_filter( 'wp_nav_menu_args', 'my_wp_nav_menu_args' ); 

    After checking the function I allready have the same problems. The Main-Menu-logged-in is displayed at all menu-positions (also in Top-Menu – avia2).
    Unfortunately this is annoying for me, because I need a menu-change strictly.
    I hope that yyou or your colleagues can help me fixing this problem.
    Thanks a lot
    Greetings
    Andreas

    #360591

    Hey!

    I would recommend to use a plugin like this one: https://wordpress.org/plugins/page-specific-menu-items/

    Regards,
    Andy

    #360710

    Hio Andy,
    thank you for your answer. I have installed this plugin. It does exactly what I want. It’s not the best solution, but it is a solution…
    So this topic is finished.
    Thanks again for the help here in the forum and
    Regards
    Andreas

Viewing 10 posts - 1 through 10 (of 10 total)
  • The topic ‘different menus, depending on whether a user is logged in or logged out’ is closed to new replies.