Title: Set a simple cookie in functions.php
Last modified: August 22, 2016

---

# Set a simple cookie in functions.php

 *  [LesTexas60](https://wordpress.org/support/users/lestexas60/)
 * (@lestexas60)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/set-a-simple-cookie-in-functionsphp/)
 * I have tried everything but I know I’m missing something simple.
    Trying to set
   a cookie when someone goes to a page. I am using the functions.php file for the
   theme for that specific page. I have multiple themes on my site. Using code: 
   function set_new_cookie() { setcookie(‘SESSIONKEY’, ‘W8FREEBTG’, 3600, ‘/’, ‘/
   les.com’); } add_action( ‘init’, ‘set_new_cookie’);
 * Anyone see why my cookie is not being set. This code is at the bottom of the 
   file. If I refresh the page shouldn’t the cookie show in the Cookie manager?

Viewing 1 replies (of 1 total)

 *  [potato5](https://wordpress.org/support/users/potato5/)
 * (@potato5)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/set-a-simple-cookie-in-functionsphp/#post-5401068)
 * Ran a quick test with your code..
 * Works:
    `setcookie('SESSIONKEY', 'W8FREEBTG');`
 * Doesnt work:
    `setcookie('SESSIONKEY001', 'W8FREEBTG', 3600);`
 * Works:
    `setcookie('SESSIONKEY002', 'W8FREEBTG', time() + 3600);`
 * The 3rd parameter “expiration date” is a Unix time stamp. Unix time started 1.1.1970.
   So 3600 seconds sets your cookie expiry date on the January 1st 1970. Means: 
   for PHP it is already expired.
 * [http://msdn.microsoft.com/en-us/library/vstudio/ms178195%28v=vs.100%29.aspx](http://msdn.microsoft.com/en-us/library/vstudio/ms178195%28v=vs.100%29.aspx)–
   > “To assign a past expiration date on a cookie”

Viewing 1 replies (of 1 total)

The topic ‘Set a simple cookie in functions.php’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [potato5](https://wordpress.org/support/users/potato5/)
 * Last activity: [11 years, 6 months ago](https://wordpress.org/support/topic/set-a-simple-cookie-in-functionsphp/#post-5401068)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
