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 a freelance WordPress developer and a contributing developer to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.

Ready to upgrade your website?

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

Let's Talk