How can I make my WordPress site redirect to subdomain once successfully login they will redirect back to root domain


When users visit my site they should login first through login form which i created in subdomain, once successfully login they will be redirected back to my root domain.

This is my subdomain ->
This is my rootdomain ->

This is my custom login form code.

$errorMsg = “”;
$validUser = $_SESSION[“login”] === true;
if(isset($_POST[“sub”])) {
$validUser = $_POST[“username”] == “admin” && $_POST[“password”] == “12345”;
if(!$validUser) $errorMsg = “Invalid Username & Password.”;
else $_SESSION[“login”] = true;

if($validUser) {

and this is my code to redirect when user visited my site

add_action( ‘get_header’, ‘wpq_my_redirection’ );

function wpq_my_redirection() {

if ( ! is_user_logged_in() ) {

wp_redirect( ‘ ‘, 302 ); die();



This code has an error of too many redirects and i think the problem here it is because the code is redirecting back in forth.

How can i make login form When succesfully login they will redirected back to the root domain without having an issue of “too many redirects”.

, , , Jaycar B. Serojano 4 years 2019-12-03T14:24:23-05:00 0 Answers 87 views 0

Leave an answer