How to set a cookie in WordPress?

Posted by Prem Tiwari | Updated on

If you want to set a cookie in WordPress? You are pretty much limited to some of the early running hooks which you can set via a plugin or activated theme’s functions.php file:

Retrieving cookies in PHP is much easier. Simply get them by name from the $_COOKIE super global, eg

Unsetting a cookie requires setting one with an expiration date in the past, something like


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers