Home > Software engineering >  Wordpress Custom Login Page can't accessible if user is logged in and will be redirect to Accou
Wordpress Custom Login Page can't accessible if user is logged in and will be redirect to Accou

Time:08-01

I need help with this case.

How to if a user is logged in are not allowed to access Login page and will be redirected to their Account Page?

I have a WordPress customized login page, and user is logged in still can access by typing /login slug

Here is my code below:

add_action( 'template_redirect', 'redirect_to_specific_page' );

function redirect_to_specific_page() {

 if ( is_page('login') && is_user_logged_in() ) {

wp_redirect( is_page('account'), 302 ); 
  exit;
     }
}

CodePudding user response:

Idk I have wrong type or something. I have change the wp_redirect( is_page('account'), 302 ); with wp_redirect( 'account', 302 ); and its fixed. Can anyone explain this?

My revision code below:

add_action( 'template_redirect', 'redirect_to_specific_page' );

function redirect_to_specific_page() {

 if ( is_page('login') && is_user_logged_in() ) {

wp_redirect( 'account', 302 ); 
  exit;
     }
}

CodePudding user response:

you can use it on wp action to redirect.

add_action( 'template_redirect', 'redirect_to_specific_page' );

function redirect_to_specific_page() {

 if ( is_page('login') && is_user_logged_in() ) {

wp_redirect( 'account', 302 );
  exit;
     }
}
  • Related