Reputation: 265
So I'm creating a wordpress plugin but I have a problem. I want logged in user to see some more pages then guests.
I thought it'd be easiest to have 2 diferent menu's so the user can edit it himself as well.
Now I ran into a problem. I created 2 menus(User-Menu and Guest-Menu) Guest menu is my primary menu.
Now I did some googling and stumbled upon this code:
function customMenu(){
if( is_user_logged_in() ) {
$args['menu'] = 'User-Menu';
}
return $args;
}
add_filter( 'wp_nav_menu_args', 'customMenu' );
Unfortunatly this causes my menu to completely dissapear. Is there something wrong with the code? I double checked the name(On spaces, Capitals etc) and couldn't find anything. I also tried the menu item id instead which wouldn't work either.
Is this code above the correct way? and if so what's the error in there? If not what is the correct way to do this from a plugin(not from a theme!)
Upvotes: 0
Views: 64
Reputation: 2905
Filters take an existing variable and modify it, so it should be an argument on your function:
function customMenu($args){
if( is_user_logged_in() ) {
$args['menu'] = 'User-Menu';
}
return $args;
}
add_filter( 'wp_nav_menu_args', 'customMenu' );
Upvotes: 1