admin管理员组

文章数量:1425884

I have found this solution ( ) 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( '', 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 ?

I have found this solution ( https://wordpress.stackexchange/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 ?

Share Improve this question asked Jun 14, 2019 at 9:19 XanderManXanderMan 32 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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' );

本文标签: phpWordpress Redirect Main Site to Subsite in Multisite Where user is NOT logged in