Display Another Menu After Login and Another Menu after Logout in WordPress
This steps is very usefull when you are wanted to display different menu when you are login or when you are logout, for example if you have a menu which has a Login in which you wanted this to replace as Dashboard or My Account menu after users or customer login to your WordPress site then the code below is usefull, so just follow the steps before adding the code.
Step 1:
Create two menu from your WordPress site and name the two menu as follows;
Menu 1: logged-in
Menu 2: logged-out
So if you create a menu 1 and consist of Home, Contact Us, Shop, My Account - so this means that menu 1 would be for login users or customers.
Then next is if you create a menu and consist of Home, Contact Us, Shop, Login - and this is for logged out users.
Then the next thing you need to do is add the code below from your WordPress functions.php Appearance>Editor>functions.php
And then paste the code on the first line of the functions.php file.
This steps is very usefull when you are wanted to display different menu when you are login or when you are logout, for example if you have a menu which has a Login in which you wanted this to replace as Dashboard or My Account menu after users or customer login to your WordPress site then the code below is usefull, so just follow the steps before adding the code.
Step 1:
Create two menu from your WordPress site and name the two menu as follows;
Menu 1: logged-in
Menu 2: logged-out
So if you create a menu 1 and consist of Home, Contact Us, Shop, My Account - so this means that menu 1 would be for login users or customers.
Then next is if you create a menu and consist of Home, Contact Us, Shop, Login - and this is for logged out users.
Then the next thing you need to do is add the code below from your WordPress functions.php Appearance>Editor>functions.php
And then paste the code on the first line of the functions.php file.
function my_wp_nav_menu_args( $args = '' ) {
if( is_user_logged_in() ) {
$args['menu'] = 'logged-in';
} else {
$args['menu'] = 'logged-out';
}
return $args;
}
add_filter( 'wp_nav_menu_args', 'my_wp_nav_menu_args' );
After that just save and it should work now.
Komentar
Posting Komentar