Archived topic
Secondary menu code
6 replies · Started by Jusung on February 22, 2023
Hello. I am trying to make secondary menu without a plugin.
So, I made 2 menus for login and logout.
Idk how this can work cuz basically, I can't set 2 secondary menu on wordpress.
So, I guess I need one menu and have to change the menu item?
`function my_wp_nav_menu_args( $args = '' ) {
if( is_user_logged_in() ) {
// Logged in menu to display
$args['secondary-menu'] = 19;
} else {
// Non-logged-in menu to display
$args['secondary-menu'] = 17;
}
return $args;
}
add_filter( 'wp_nav_menu_args', 'my_wp_nav_menu_args' );
Hi there,
what is the actual requirement ?
Are you wanting to show a different menu for a logged in user ?
Yes. I want to make a conditional menu for logined in user.
loged in: logout, my account
loged out: login, register
to make this, I created 2 menu to switch depending on the condition.
However, it is a secondary menu and I can't set 2 secondary menu.
Therefore, the code above doesn't seem to work.
I guess I just have to have one menu and switch only menu item?
Hi Jusung,
Our recommendation for this would be to use a plugin called Conditional Menus: https://wordpress.org/plugins/conditional-menus/
It is settled.
I refered this
https://generatepress.com/forums/topic/conditional-menus-php-snippets/
and it works!
Glad you resolved it!
I will mark this as resolved