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 badges1 Answer
Reset to default 0Try 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' );