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 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' );
本文标签: phpWordpress Redirect Main Site to Subsite in Multisite Where user is NOT logged in
版权声明:本文标题:php - Wordpress: Redirect Main Site to Subsite in Multisite Where user is NOT logged in 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745403301a2657135.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论