PHP header() gives headers already sent
I had to do it with WordPress’s inbuilt redirect function; wp_redirect(); wp_redirect( $payment->getPaymentUrl() ); exit;
I had to do it with WordPress’s inbuilt redirect function; wp_redirect(); wp_redirect( $payment->getPaymentUrl() ); exit;
Hooking action once but called twice
$wpdb->insert running multiple times?
Fire on widgets_init only on dashboard
Init plugin again after ajax call finish
Hooking to admin_init is what you want, for doing a redirect while inside admin. So you’d need both – that one, and the hook to template_redirect for the front-end handler.
Contact Form 7 – Uncaught TypeError: wpcf7.initForm is not a function [closed]
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 ); … Read more
template_redirect and wp (as the OP noted in comments) are good hooks to do this. But there’s a problem of logic in the sample code. I think it should be like: add_action( ‘template_redirect’, ‘cookie_redirect_wpse_113662’ ); function cookie_redirect_wpse_113662() { # No cookie set, let’s do it if( !isset( $_COOKIE[‘site_language’] ) ) set_cookie_wpse_113662( ‘ar’ ); # One … Read more
The add_rewrite_rule function doesn’t change the database. Just an array in memory. It is not an expensive operation. The alternative is to add code to detect whether your rule is there, which is actually more expensive than just modifying the array.