Tagged: menu
-
AuthorPosts
-
November 15, 2014 at 10:44 am #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
AndreasNovember 16, 2014 at 5:27 pm #352066Hi 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 10 years ago by Elliott.
November 26, 2014 at 9:50 pm #358572This reply has been marked as private.November 28, 2014 at 1:41 am #359330Hi!
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,
ElliottNovember 28, 2014 at 9:50 am #359465Hey 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
AndreasNovember 28, 2014 at 8:44 pm #359868Hey!
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, 12 months ago by Elliott.
November 29, 2014 at 1:08 am #359982Hi 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
AndreasNovember 29, 2014 at 1:59 pm #360070Hi 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
AndreasDecember 1, 2014 at 5:19 am #360591Hey!
I would recommend to use a plugin like this one: https://wordpress.org/plugins/page-specific-menu-items/
Regards,
AndyDecember 1, 2014 at 11:57 am #360710Hio 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 -
AuthorPosts
- The topic ‘different menus, depending on whether a user is logged in or logged out’ is closed to new replies.