Skip to content

Instantly share code, notes, and snippets.

@cheh
Forked from billerickson/mobile.php
Created March 11, 2014 19:40
Show Gist options
  • Save cheh/9493459 to your computer and use it in GitHub Desktop.
Save cheh/9493459 to your computer and use it in GitHub Desktop.
<?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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment