I am growing a plugin and I have to redirect to not logged in customers to a {custom} login web page on frontend so I wrote:
add_action( 'template_redirect', 'redirect_if_not_logged_in' );
operate redirect_if_not_logged_in() {
if ( ! is_page('slug') && ! is_user_logged_in() ) {
wp_redirect( 'custom-login-page' ) );
die();
}
}
It really works however now I have to redirect logged in customers to house web page in the event that they attempt to entry immediately (typing URL) to {custom} login web page. If I add an else
in redirect_if_not_logged_in I get an infinite loop…