As I have searched for the answer to this question, I have found quite a few answers that have worked for other folks. However, none of the solutions have worked for me, so I am forced to ask the question here.

I am trying to check whether a cookie has been set and redirect to a page if the cookie has not been set. However, my redirect keeps getting in an endless loop.

I have put the following code in my functions.php file:

function pure_user_type() {
    if (isset($_COOKIE['pure_visitor'])) {

    }
    else {
        setcookie('pure_visitor', 1);
        wp_redirect( get_site_url() . '/user-type/'));
        exit();
    }
}
add_action( 'init', 'pure_user_type');

Any help would be appreciated.

Read more here: wp_redirect() creating an endless loop


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: