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

Related posts

2 comments

  1. 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');
    
  2. You can work with javascript, add this code:

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

Comments are closed.