简体   繁体   English

wp_redirect在插件上不起作用

[英]wp_redirect not working on plugin

I create a worpdress plugin, and I have a big problem, wp_redirect is not working. 我创建了一个worpdress插件,但我遇到了一个大问题,wp_redirect无法正常工作。
this is my code: 这是我的代码:

<?php
if (is_user_logged_in())
{
echo 'loggedin';
}
else
{
echo network_home_url( '/receptionist' );
wp_redirect( network_home_url( '/receptionist' ) );
exit;
}
?>

I also try wp_safe_redirect and header to redirect, but no result. 我也尝试使用wp_safe_redirect和header进行重定向,但是没有结果。
Can some one help me to found the error 有人可以帮我发现错误吗

Try following 尝试跟随

function wp5673fg_redirect()
{
    if (is_user_logged_in())
    {
        echo 'loggedin';
    }
    else
    {
        wp_safe_redirect(network_home_url('/receptionist'));
    }
}
add_action('init', 'wp5673fg_redirect');

您可以使用javascript,添加以下代码:

window.location= <?php echo "'" . $redirect_url."'"; ?>;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM