The setcookie
function prepares the HTTP cookie header to be sent at the next page load. That’s why the $_COOKIE
superglobal is not updated automatically.
You could manually update $_COOKIE
for use on the current request. Just put this below your setcookie()
line:
$_COOKIE['mobileesp_wp_full_site'] = 'true';
By the way, I’d prefer not to work with strings like 'true'
, but just with integers (0
and 1
). You then can simply check them like this: ! empty($_GET['view_full_site'])
.