0

I have found this solution ( https://wordpress.stackexchange.com/questions/66115/redirect-main-site-to-subsite-in-multisite-wordpress ) regarding redirecting a mainsite to a subsite in wordpress.

But!

What IF I only want this to happen when a user is not logged in ? I tried to change the code to this, but without any success..

  <?php
function wpse66115_redirect_to_sub_site() { 
  if ( is_user_logged_in() && is_main_site() ) {
    exit( wp_redirect( 'http://old.heiledeg.no', 301 ) );
  }
}
add_action( 'parse_request', 'wpse66115_redirect_to_sub_site' );
?>

I also tried using an ELSE statement. But it seems the argument ignores the "is_user_logged_in" argument.

Any ideas ?

1 Answer 1

0

Try this

function wpse66115_redirect_to_sub_site() { 
  if ( is_main_site() ) {
      if ( is_user_logged_in() ) {
      } else {
        exit( wp_redirect( 'http://old.heiledeg.no', 301 ) );
      }
  }
}
add_action( 'parse_request', 'wpse66115_redirect_to_sub_site' );
2
  • thank you. It seems to be working now.
    – XanderMan
    Jun 14, 2019 at 9:42
  • you are welcome
    – Gregory
    Jun 14, 2019 at 12:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.