You need to separate the redirect function from the setcookie function
For setcookie function use add_action('wp', 'your_cookies_function_name',10,1)
Note that it’s recommended to use wp
and not init
because is_page
will not work with init
And for the redirect function:
function your_redirect_function_name()
{
if(is_page('uae') && $_COOKIE_['region'] !== "UAE"){
wp_redirect('http://domain.com/uae/');
exit();
}
}
add_action( 'template_redirect', 'your_redirect_function_name',9 );
For more information navigate to this page How to setcookie if is_page(‘page’) ? should I use add_action(‘init’) or there is another action?
I had same problem and I fix it my self