I have written a plugin that sets cookies, and need to avoid the "Headers already sent" PHP error by placing the code at the very top before the head section. Themes usually place wp_head just before the close of the head section, so is there any efficient way to get a plugin to send this code without having to edit the theme itself?
For that I would suggest to use
'init'
hook.
According to codex
This runs after WordPress has finished loading but before any headers are sent
For more details visit codex explantion and examples for this hook;
You can find answer to similar question over here;
-
1Good to know that this worked for you. Just up vote and mark it as right answer so that it would help others as well. – Mohammad Mursaleen Nov 23 '14 at 12:44
-
@josh if this worked for you; can you mark it as right answer so that it could help others as well. – Mohammad Mursaleen Aug 21 '15 at 18:41
<head>
section of the html you generate. The http header contains information like the content-type of the body, and once you start emitting the body, you can't change the header anymore (as the header already has been sent to the client). – Femaref Nov 23 '14 at 14:56