Set Cookies in wordpress

Using this blow code you can set cookies using wordpress

1.Paste this code where you want to set cookies
Like header.php footer.php or particular page you can set cookies.
{ $last = $_COOKIE['AboutVisit']; echo "Welcome back! <br> You last visited on ". $last;
 } else 
{ echo "Welcome to our site!"; 

2.Add below code into Function.php


  function my_setcookie() {
 $Month = 1000 + time();
 //this adds 30 days to the current time
 setcookie(AboutVisit, date("F jS - g:i a"), $Month);

 add_action('init', 'my_setcookie');?>

One thought on “Set Cookies in wordpress

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s