Hi
I want to use conditional logic on the MAIN MENU for LOGGED-IN & LOGGED-OUT members on my site. I have tried several pluggins including “IF MENU” & “MENU ITEM VISIBILITY CONTROL” but to no avail.
What is the best way to accomplish this?
Hi,
Follow these steps:
1. First you have to register the new-menu, for that go to td_menu.php file and add this line: http://screencast.com/t/WJy9nhodUS
'header-menu-login' => __( 'Header Menu login (main)', TD_THEME_NAME),
You will get this result: http://screencast.com/t/ihF4cmqRgq
2. Secound go to menu-header.php file and add this condition like, this: http://screencast.com/t/OtKQsOJosx0
if ( is_user_logged_in() ) {
wp_nav_menu(array(
'theme_location' => 'header-menu-login',
'menu_class'=> 'sf-menu',
'fallback_cb' => 'td_wp_page_menu',
'walker' => new td_tagdiv_walker_nav_menu()
));
} else {
wp_nav_menu(array(
'theme_location' => 'header-menu',
'menu_class'=> 'sf-menu',
'fallback_cb' => 'td_wp_page_menu',
'walker' => new td_tagdiv_walker_nav_menu()
));
}
3. Do the same for mobile menu, into menu-mobile.php file: http://screencast.com/t/3CQa5fpkw
if ( is_user_logged_in() ) {
wp_nav_menu(array(
'theme_location' => 'header-menu-login',
'menu_class'=> '',
'fallback_cb' => 'td_wp_no_mobile_menu'
));
} else {
wp_nav_menu(array(
'theme_location' => 'header-menu',
'menu_class'=> '',
'fallback_cb' => 'td_wp_no_mobile_menu'
));
}
After this set which menu you want for logged visitors and which for unregistered visitors and test it.
Hope this helps!
Sorry for the delay!
Thanks
THanks ! But I guess it doesn’t work in a child theme… Isn’t It ?
Hi,
@mike I provided this topic just for reference and this code works for Newspaper 4(like I told you in the other topic). You can register the new menu like this – http://screencast.com/t/QfsK0NIYp3Lg and here you can add your menu using a condition(if you want) – http://screencast.com/t/x7P9EshsqKbF
Thanks!
Hi
The only change that must be done is at point 1: the new nav-menu must be registered in td-menu.php
like this: http://screencast.com/t/qqX2Ht3AFOlo The steps 2 and 3 are the same.
Thanks!
Hello Andrei
It has worked quiet fine. But I need to make available the menu for 3 cases:
– Public menu (logged off users)
– Private users menu (logged in as Users role)
– Suscribers menu (logged in as Suscribers role)
Please, could you help me with it?
Thank you in advance
Hi
You need to register a new menu using the above method. Also you will need a condition which display that menu only if the current user is a subscriber. Your code will look like this: http://screencast.com/t/qwCCbvE1 – http://screencast.com/t/XnidFPu3nH – http://pastebin.com/XC9BUxFJ
Thanks!
