简体   繁体   中英

wp_redirect not working on plugin

I create a worpdress plugin, and I have a big problem, wp_redirect is not working.
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.
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."'"; ?>;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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