Reputation: 924
I've got this wordpress site. And i've made two menu's. One which is supposed to be shown when a user isn't logged in, and one for when a user is logged in. And i'm talking about a login to the website it self, not the dashboard.
How do I make the menu's change, from the one I have where I am not logged in, to the one where I am?
I've tried adding the following code to the functions.php page, but it isn't working.
function my_wp_nav_menu_args( $args = '' ) {
if(session_status() != PHP_SESSION_NONE ) {
$args['menu'] = 'logged-in';
} else {
$args['menu'] = 'logged-out';
}
return $args;
}
add_filter( 'wp_nav_menu_args', 'my_wp_nav_menu_args' );
I'm not sure where to look next, and I can't find any solutions on google. Hope someone can help me out!
I've also made sure i got the session_start(); at the top of every .php page.
Upvotes: 2
Views: 306
Reputation: 11
You can make 2 different menus and use a simple if else :
<?php
if ( is_user_logged_in() ) {
wp_nav_menu( array( 'theme_location' => 'registered-menu' ) );
} else {
wp_nav_menu( array( 'theme_location' => 'visitor-menu' ) );
}
?>
Upvotes: 1