The Problem:
Adding LogIn / LogOut links to WordPress menus depending on whether the user is logged in or out
The Solution:
1- Install the 'Login Logout Menu': https://wordpress.org/plugins/login-logout-menu/
2- Add to functions.php
/**
* Filter to redirect a user to a specific page after login.
*
* @return [URL] login url with page slug on which it will be redirected after login
*/
add_filter( 'login_logout_menu_login', 'loginpress_login_menu_login_redirect' );
function loginpress_login_menu_login_redirect()
{
return wp_login_url( '/members' );
}
/**
* Filter to redirect a user to a specific page after logout.
*
* @return [URL] logout url with page slug on which it will be redirected after logout
*/
add_filter( 'login_logout_menu_logout', 'loginpress_login_menu_logout_redirect' );
function loginpress_login_menu_logout_redirect()
{
return wp_logout_url( '/' );
}
No comments:
Post a Comment