Support » Fixing WordPress » set cookies in template ?
7 years, 11 months ago
I spend last 4 hours to try to set cookies in wordpress and look around for any solution… but i didn’t find anything.
Cookies are enabled in my browser ( firefox 3 ) and in the admin section wordpress cookies are set perfectly.
But if i want to set my own cookies in the header of my template it’s not working.
I tried this :
setcookie (“test”, “actif”, time()+3600);
And this :
setcookie (“test”, “actif”, time()+3600, “/”, “localhost” );
no results at all… it look like we can’t set cookies in a template.
I didn’t find anything about that in google so i think i’m doing something wrong.
Ok i just found the solution… I put that here for other with the same problem.
I’m almost sure now, you can’t set cookies in the header or footer or any template part.
You can only set cookies in a plugin or in the function.php of your template.