this is pretty straight forward: How do I redirect mobile users to /mobile, but still allow them to click a "Full site" button and see the full site without being redirected again back to the mobile site?

I have played with a bunch of the plugins that say they do this, but none seem to handle the second step. They redirect to the /mobile . but if a user wants to go to the full site, it tries then redirects back to mobile.

I am running WP3.0.1

4 Answers 4

function mobile_redirect() {
    if (isset($_COOKIE["redirected"]) && $_COOKIE["redirected"])
    global $is_iphone;
    if( isset($is_iphone) && $is_iphone ) {
        wp_redirect( '/mobile/' );
        setcookie("redirected", true);
add_action('init', 'mobile_redirect');

This code redirects every mobile visitor to /mobile/ and then sets a cookie that the user is redirected. If the cookie is set, then the redirect doesn't take place. So if the user again goes to your site it won't redirect to the mobile url.

You can also set the cookie if there is a variable in the url, like /?v=desktop, then if that url is visited it sets the cookie and doesn't redirect anymore.


Use of builtin $is_iphone variable; Thx to Kaiser.

Btw: strange name for a variable that's used for every mobile device. $is_mobile would be a better name.

  • 1
    WP has already the built in global $is_iphone; that triggers for all sorts of mobile devices. No need to again check with a slow preg_match for that. Upvote anyway.
    – kaiser
    Commented Jan 16, 2012 at 17:49
  • 1
    Thx Kaiser, updated my answer. Commented Jan 16, 2012 at 18:49

I agree with Shaun. If you design your current theme well, you can just make it so that mobile devices use a different stylesheet. So basically you'll only need one theme, just two different style variants.

Example code used for changing stylesheets based on desktop or mobile device site access:

// Function in functions.php file

function is_mobile_device(){
    $device = '';

    if( stristr($_SERVER['HTTP_USER_AGENT'],'ipad') ) {
        $device = "ipad";
    } else if( stristr($_SERVER['HTTP_USER_AGENT'],'iphone') || strstr($_SERVER['HTTP_USER_AGENT'],'iphone') ) {
        $device = "iphone";
    } else if( stristr($_SERVER['HTTP_USER_AGENT'],'blackberry') ) {
        $device = "blackberry";
    } else if( stristr($_SERVER['HTTP_USER_AGENT'],'android') ) {
        $device = "android";

    if( $device ) {
        return true; 
    } return false; {
        return false;

 // Code in header.php

<?php if (is_mobile_device()) { 
   } else {

I'm using Obox Mobile on my website (http://clickwp.com) and it works really well even with W3 Total Cache. You can switch to the full site with no problem.

Although I agree that a responsive theme is probably the best way to go if you're looking for an easy solution. As you can see from my site, the sideshow gallery doesn't scale. A well-built responsive theme would take these into consideration as its not relying on a 3rd party plugin to provide the mobile functionality.

That being said, Obox Mobile is a good solution for me until I have the time and money to make my site responsive. Please use my affiliate link if you want to buy it, thanks!



Check the $is_iphone; variable. Then do your own redirects.

  • This makes sense in general. I have had no problem forwarding the user to the mobile site, my main issue is when the mobile user wants to come back to the main site the redirect sends them back to the mob site. Commented Jan 13, 2012 at 21:30
  • Plugins won't solve your edge case task. As I said: "do your own redirects". I gave you the knife, now cook :)
    – kaiser
    Commented Jan 13, 2012 at 21:38
  • 1
    You could add a query var when returning from the mobile site, and check if it exists before the redirect starts.
    – Mario
    Commented Jan 13, 2012 at 22:10
  • 1
    Using responsive design and media queries you won't need to build a separate mobile site at all, and so won't need redirection.
    – Shaun
    Commented Jan 13, 2012 at 23:22
  • 1
    The var just triggers for every "mobile" device, not just the iPhone. The name is missleading...
    – kaiser
    Commented Jan 14, 2012 at 15:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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