Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

bkeetman on "Disable switching to mobile theme from certain theme pages"

$
0
0

I am working on a WordPress plugin and theme which does a template switch if server side it is detected the user is visiting the site via a mobile device.

Something like this:

$iphone = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone");
$ipod = strpos($_SERVER['HTTP_USER_AGENT'],"iPod");
$android = strpos($_SERVER['HTTP_USER_AGENT'],"Android");
$palmpre = strpos($_SERVER['HTTP_USER_AGENT'],"webOS");
$berry = strpos($_SERVER['HTTP_USER_AGENT'],"BlackBerry");
$iemobile = ( strpos($_SERVER['HTTP_USER_AGENT'],"iemobile") || strpos($_SERVER['HTTP_USER_AGENT'],"IEMobile") );

if ( ( $iphone || $android || $palmpre || $ipod || $berry !== FALSE || $iemobile ) === true )
{
   // echo 'going to mobile';
    add_filter('stylesheet', function() {
        return '2012aanbiedingen-mobile';
    });
    add_filter('template', function() {
        return '2012aanbiedingen-mobile';
    });
}

So there is a separate desktop theme and a mobile theme.
Obviously I want to switch to the correct theme (mobile or desktop) via the plugin.. so before I actually load one of them. (Or I would always be loading the desktop one.. and some times switch to the mobiel theme).
This all works fine for now.

But now I am planning to move some pages over to be responsive. What I ideally would like to do is set a variable (or execute a hook what ever) in the top of the theme which will let the plugin know.. "no need to switch to the mobile theme. Keep the desktop version."

What would be the best way to handle this?
Are there specific hooks that could help?
Would I always need to render the desktop theme and then decide if the theme needs to switch to mobile etc.

Any advice would be great :)


Viewing all articles
Browse latest Browse all 8245

Trending Articles