I am trying to make a simple plugin that welcomes users when they visit the site for the first time but I keep getting a 'headers already sent' error.
I know this error has something to do with the cookie not being sent in the header. And I already found some solutions but none that work within the plugin. Can I do all this inside the plugin ? (I'm trying to write this inside a wordpress widget)
if (!isset($_COOKIE['visited'])) {
setcookie ('visited', 'yes', time() + 3600);
echo "Welcome.";
}
else{
echo "Welcome back";
}
So if a user visits the site for the first time I want him to see 'Welcome' but if he is a returning visitor, I want to display 'welcome back',