Setting Cookie with init hook causes ‘header already sent’
Based on research here and elsewhere, I have the following code that sets a cookie on a site: add_action( ‘init’, ‘my_set_cookie’,1 ); function my_set_cookie() { if (! $_COOKIE[‘mycookie’]) { $guid = ‘xxxx’; // normally a real guid value so it will be unique setcookie(‘mycookie’, $guid, time()+(3600*24*30),”https://wordpress.stackexchange.com/”); } return; } But even though the init hook … Read more