my code is
add_action('init', 'user_logged_in');
function user_logged_in(){
if( is_user_logged_in() && is_page('login')){
wp_redirect(home_url());
exit;
}
}
the page slug and name is "login"
I do not want the logged in member to access the login page.
But this code does not work in functions.php.
Can you tell me what went wrong?
init
is too early to determineis_page()
. Try a later hook, liketemplate_redirect
.