title: How to set a cookie in Wordpress
body: <p>I'm trying to set a cookie in wordpress. I have my cookie set like this :</p>
  
  <pre><code>&lt;?php setcookie('test', 'test', 0, '/', '/');  ?&gt;
  </code></pre>
  
  <p>in header.php of my theme, but when I go to my browser to view my website I get this error</p>
  
  <pre><code>Warning: Cannot modify header information - headers already sent by (output started at /home/content/19/9468119/html/wp-content/themes/twentyeleven/header.php:27) in /home/content/19/9468119/html/wp-content/themes/twentyeleven/header.php on line 201
  </code></pre>
  
  <p>and also my cookie doesnt set. How do I set a cookie in wordpress?</p>
  
  <p>I have also tried this</p>
  
  <pre><code> function set_new_cookie() {
      setcookie('test', 'test', 0, '/', '/');
  }
  add_action( 'init', 'set_new_cookie');
  </code></pre>