It can be really useful to know if a visitor is a returning visitor. A good example would be to check if someone’s coming back to your eCommerce site and have items still in their basket. You can then display a notification.

Add this to your functions.php.

function set_newuser_cookie() {
	if ( !is_admin() && !isset($_COOKIE['sitename_newvisitor'])) {
		setcookie( 'sitename_newvisitor', 1, time()+3600*24*100, COOKIEPATH, COOKIE_DOMAIN, false);
add_action( 'init', 'set_newuser_cookie');

Then you can call the function anywhere, such as single.php or header.php

if (isset($_COOKIE['sitename_newvisitor'])) {
		 $returningvisitor = true;
	else {
		 $returningvisitor = false;

Leave a Reply