Created
May 14, 2013 03:39
-
-
Save wookiecooking/5573499 to your computer and use it in GitHub Desktop.
[WordPress] Mobile Theme Switcher + IPad View
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Mobile Theme Switch | |
Description: Switches WordPress theme based on user agent | |
*/ | |
session_start(); | |
if($_GET['mobile'] == "off"){ | |
$_SESSION[$mobilethemeswitch] = "off"; | |
} else if($_GET['mobile'] == "on"){ | |
$_SESSION[$mobilethemeswitch] = "on"; | |
} | |
//mobile browsers | |
$iphone = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone"); | |
$ipod = strpos($_SERVER['HTTP_USER_AGENT'],"iPod"); | |
$android = strpos($_SERVER['HTTP_USER_AGENT'],"Android"); | |
$ipad = strpos($_SERVER['HTTP_USER_AGENT'],'iPad'); | |
$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 || $berry || $ipod || $iemobile) == $_SERVER['HTTP_USER_AGENT'])) { | |
add_filter('stylesheet', 'mobile'); | |
add_filter('template', 'mobile'); | |
} | |
if ((($ipad) == $_SERVER['HTTP_USER_AGENT']) ){ | |
add_filter('stylesheet', 'mobilePad'); | |
add_filter('template', 'mobilePad'); | |
} | |
function mobile(){ | |
$mobiletheme = ' MOBILE PHONE TEMPLATE '; | |
$themes = get_themes(); | |
foreach ($themes as $theme_data) { | |
if ($theme_data['Name'] == $mobiletheme) { | |
return $theme_data['Stylesheet']; | |
} | |
} | |
} | |
function mobilePad(){ | |
$mobiletheme = ' IPAD TEMPLATE HERE '; | |
$themes = get_themes(); | |
foreach ($themes as $theme_data) { | |
if ($theme_data['Name'] == $mobiletheme) { | |
return $theme_data['Stylesheet']; | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment