-
-
Save turtlepod/4170650 to your computer and use it in GitHub Desktop.
Load a different WordPress theme for mobile visitors
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: Unplugged Mobile Theme | |
Plugin URI: http://www.rachelbaker.me | |
Description: A plugin and theme for WordPress that automatically reformats your blog's content for optimized viewing on Apple's <a href="http://www.apple.com/unplugged/">unplugged</a> and <a href="http://www.apple.com/ipodtouch/">iPod touch</a>. | |
Author: Rachel Baker | |
Version: 0.1 | |
Author URI: http://www.rachelbaker.me | |
# Special thanks to Imthiaz Rafiq and the wp-pda Plugin (http://imthi.com/wp-pda/) which this plugin is derived from. | |
# This plugin is free software; you can redistribute it and/or | |
# modify it under the terms of the GNU Lesser General Public | |
# License as published by the Free Software Foundation; either | |
# version 2.1 of the License, or (at your option) any later version. | |
# | |
# This plugin is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
# Lesser General Public License for more details. | |
# | |
# You should have received a copy of the GNU Lesser General Public | |
# License along with this plugin; if not, write to the Free Software | |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
*/ | |
class UnpluggedMobile{ | |
var $unplugged; | |
function UnpluggedMobile(){ | |
$this->unplugged = false; | |
add_action('plugins_loaded',array(&$this,'detectunplugged')); | |
add_filter('stylesheet',array(&$this,'get_stylesheet')); | |
add_filter('template',array(&$this,'get_template')); | |
} | |
function detectunplugged($query){ | |
if(preg_match('/(alcatel|amoi|android|avantgo|blackberry|benq|cell|cricket|docomo|elaine|htc|iemobile|iphone|ipad|ipaq|ipod|j2me|java|midp|mini|mmp|mobi|motorola|nec-|nokia|palm|panasonic|philips|phone|sagem|sharp|sie-|smartphone|sony|symbian|t-mobile|telus|up\.browser|up\.link|vodafone|wap|webos|wireless|xda|xoom|zte)/i', $_SERVER['HTTP_USER_AGENT'])) { | |
$this->unplugged = true; | |
} | |
} | |
function get_stylesheet($stylesheet) { | |
if($this->unplugged){ | |
return 'unplugged-mobile-theme'; | |
}else{ | |
return $stylesheet; | |
} | |
} | |
function get_template($template) { | |
if($this->unplugged){ | |
return 'unplugged-mobile-theme'; | |
}else{ | |
return $template; | |
} | |
} | |
} | |
$wp_unplugged = new UnpluggedMobile(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment