Mobile Theme Switcher

<?php
/**
*
* Mobile theme switcher code - pulled from Mobile theme switch
* Original URI: http://wordpress.org/extend/plugins/mobile-theme-switcher/
* Original Author: Jonas Vorwerk, http://www.jonasvorwerk.com/
*
*
* Bypass this check in any browser by using http://myurl/?mobile=on or http://myurl/?mobile=off This is locally being stored using a cookie.
*
* param $themes - set to genesis (parent theme)
* param $style - set to child theme directory name (child theme)
*
*/
if( is_admin() )
return;
session_start();
if( !isset( $_SESSION['mobilethemeswitch'] ) )
$_SESSION['mobilethemeswitch'] = '';
if( isset( $_GET['mobile'] ) && $_GET['mobile'] == "off"){
$_SESSION['mobilethemeswitch'] = "off";
} else if( isset( $_GET['mobile'] ) && $_GET['mobile'] == "on"){
$_SESSION['mobilethemeswitch'] = "on";
}
//mobile browsers - this list can be expanded as needed
$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) || $_SESSION['mobilethemeswitch'] == "on") && $_SESSION['mobilethemeswitch'] != "off" ) {
add_filter('stylesheet', 'getThemeStyle');
add_filter('template', 'getTemplateStyle');
}
function getTemplateStyle(){
$themes = 'genesis';
return $themes;
}
function getThemeStyle(){
$style = 'dcsi-mobile';
return $style;
}
view raw mobile.php hosted with ❤ by GitHub

Bill Erickson

Bill Erickson is the co-founder and lead developer at CultivateWP, a WordPress agency focusing on high performance sites for web publishers.

About Me
Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk