Hi
I’m trying to change the top bar menu as I’ve been able to do with the main menu (see working sample below).
When i run the code below it also changes the top bar menu to the menu called ‘Main-Menu-Logged-In’.
What I’m actually trying to achieve is for the top bar menu ONLY to change depending on user login. I just don’t know how to call it successfully like the main menu.
Heeelp please!
function my_wp_nav_menu_args( $args = '' ) {
if( SwpmMemberUtils::is_member_logged_in() ) {
$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' );
Hi,
This is where the top menu is being called in the theme
– https://www.screencast.com/t/EvrXIQuBli
You could create the condition there, only for the menu
– https://developer.wordpress.org/reference/functions/is_user_logged_in/
Follow these topics for more information
– https://forum.tagdiv.com/topic/conditional-logic-for-menu/
– https://forum.tagdiv.com/topic/how-to-register-a-second-menu-for-woocommerce-pages/
Thanks
Hi
Thanks for the reply. I’m still unsure on how to call the top menu and set a different menu to it?
I’m using a child theme if that changes anything. I’m calling the code below in functions.php.
I tried this:
function my_wp_nav_menu_args( $args = '' ) {
if( SwpmMemberUtils::is_member_logged_in() ) {
$args['tds_top_menu'] = 'Top-Bar-Menu-Logged-In';
echo "Logged in";
} else {
$args['tds_top_menu'] = 'Top-Bar-Menu-Logged-Out';
echo "Logged out";
}
return $args;
}
add_filter( 'wp_nav_menu_args', 'my_wp_nav_menu_args' );
-
This reply was modified 9 years by
mkastrupsen.
Update:
I have tried following some of the links you sent but the screenshots doesnt work anymore.
I have registered the menus in td_menu.php like this:
https://www.screencast.com/t/WvDlzfNLcJc
Then i assigned the menus to the locations in the Menu Locations panel in wordpress.
So now, where and how do i call them?
I tried calling this in the top-header.php (the condition i check is for a member, and that works. It’s only the code inside the conditional statement that’s not working):
<code>
if( SwpmMemberUtils::is_member_logged_in() ) {
wp_nav_menu(array( 'theme_location' => 'Top-Bar-Menu-Logged-In',
'menu_class'=> 'sf-menu',
'fallback_cb' => 'td_wp_page_menu',
'walker' => new td_tagdiv_walker_nav_menu()
));
} else {
wp_nav_menu(array( 'theme_location' => 'Top-Bar-Menu-Logged-Out',
'menu_class'=> 'sf-menu',
'fallback_cb' => 'td_wp_page_menu',
'walker' => new td_tagdiv_walker_nav_menu()
));
}
</code>
Does not work. What do i do wrong?
-
This reply was modified 9 years by
mkastrupsen.
Hi,
A simple condition like this seems to work, after registering the new menu
– https://www.screencast.com/t/82FZ2bAf2rQ
– https://www.screencast.com/t/nsNXSHPlw
If the current user is logged in, a menu will be displayed
– https://www.screencast.com/t/g6UXjbhyR
If it is not, a different menu will be displayed instead
– https://www.screencast.com/t/kqRVYhe7e
Thanks
Thanks. That worked 🙂
Another question. I just installed the mobile theme plugin, and some of the sites do not show. I use a membership plugin and that page is completely empty on the mobile version now. I’m using a child theme if that makes any difference.
What could be going on?
Hi,
Content for pages when using the mobile theme plugin, is limited to the mobile editor
– https://www.screencast.com/t/CgYseBYvafj
This section appears in the page edit screen when the mobile theme is active.
For performance factors and speed, the mobile theme will not display composer elements and shortcodes. That may be why the pages are empty.
Please note that the mobile plugin is optional, if you want the same content from desktop to display on mobile devices simply deactivate it. The theme is fully responsive and will adapt to all devices.
Here you can find more information about the mobile theme
– https://forum.tagdiv.com/the-mobile-theme/
Thanks
Is there a way to show a different main menu when it’s viewed on a mobile phone without using the mobile theme plugin?
I need to be either able to show the top bar on mobile without the mobile theme plugin, or show a different main menu on the mobile version.
I had to disable the mobile theme plugin since you said it doesn’t work with shortcodes. I’m using a membership plugin that uses shortcodes which won’t show using the mobile theme plugin.
-
This reply was modified 9 years by
mkastrupsen.
Having the top menu display on mobile when tapping the 3 horizontal lines in the upper left corner on mobile to show the main menu on mobile would totally work.
How can i do that? It’s viteea.com
I want the top bar from the desktop version top be displayed where i just mentioned above.
Hi,
You could try a code like this one, and it will make the top menu visible on mobile as well
– https://www.screencast.com/t/vLxErQSO6d
.td-header-top-menu-full,
.top-bar-style-2 .td-header-sp-top-menu {
display: block!important;
float:none;
text-align:center;
}
The code must be entered in Theme panel->Custom Css, if you decide to use it.
Unfortunately I cannot test this on your website at the moment, it seems to require login information
– https://www.screencast.com/t/jIKHfwgl5lf9
The top menu will be displayed at the top, it is not part of the main menu container and it cannot be displayed along inside it. Normally the top menu is not displayed on mobile, there is a possibility that this solution may not work properly.
Thanks
Hi. That worked, but there is a problem when scrolling. See this short vidoe i made: https://www.youtube.com/watch?v=1_kRyXGs5Vk
Can you help with that?
Hi,
I cannot view your website at the moment
– https://www.screencast.com/t/hvwBU3tuTt6
But as I said before this workaround may not work properly, since the top menu is not supposed to be present on mobile. It may require additional modifications to it, or to other header elements.
Thanks
Hi. Can you just take a look at the video? You can view the site now also.
Hi,
I have carefully tested it both on mobile and emulator but this is not happening for me
– https://www.screencast.com/t/KJOtCJKld1W
– https://www.screencast.com/t/3hpWE2d3rcGZ
The top menu does not interfere with the main menu in my tests. Try testing with different sticky menu settings and see if it is still happening
– https://www.screencast.com/t/xSKPdabON
Thanks
Hi,
Your suggestion seems to be working A LOT better. Thanks!
-
This reply was modified 9 years by
mkastrupsen.