wp_redirect() creating an endless loop

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/'));
add_action( 'init', 'pure_user_type');

Any help would be appreciated.

Read more here: wp_redirect() creating an endless loop

Leave a Reply

Your email address will not be published. Required fields are marked *