WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I wrote a small WordPress plugin (mobileesp-for-wordpress) that will redirect mobile users to the mobile site. It's based on mobileesp.

The plugin itself works fine the problem is I added an option to view the full site. This function works by checking for a cookie and if the cookie is there don't redirect the user to the mobile site.

This also works but the user must click the link twice. Once to set the cookie and the second time to take them back into the WordPress site. The full code can be found here but I think this is the relevent part.

$get_cookie_check = $_GET['view_full_site'];
    if($get_cookie_check =='true'){
        //set the cookie
        setcookie("mobileesp_wp_full_site", 'true', time()+86400, "/", $domain);
//cookie variable
$full_site_cookie= $_COOKIE['mobileesp_wp_full_site']; 

//make sure the target url is set and full site cookie isn't set
if((get_option('mobileesp_wp_target_url') != '') && ($full_site_cookie !="true")){
    //check for a mobile browser and redirect the user 


The temporary solution would be to check for the cookie on the mobile site then redirect them but is there a better way to do this.

share|improve this question
up vote 2 down vote accepted

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']).

share|improve this answer
I took your advice and am not using 0 and 1 for cookie values thanks! – BandonRandon Nov 13 '11 at 21:23

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.