<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Digging into WordPress &#187; mobile</title>
	<atom:link href="http://digwp.com/tag/mobile/feed/" rel="self" type="application/rss+xml" />
	<link>http://digwp.com</link>
	<description>Take your WordPress skills to the next level.</description>
	<lastBuildDate>Fri, 18 May 2012 18:21:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Redirect Mobile Users to a Mobile WordPress Theme</title>
		<link>http://digwp.com/2009/12/redirect-mobile-users-to-mobile-theme/</link>
		<comments>http://digwp.com/2009/12/redirect-mobile-users-to-mobile-theme/#comments</comments>
		<pubDate>Mon, 07 Dec 2009 13:57:04 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[Theme]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=1032</guid>
		<description><![CDATA[Let&#8217;s say you want to have a special theme for your WordPress site for mobile users. You don&#8217;t want to use a pre-canned solution or anything third-party, you just want to create and design the theme yourself. So what you need to happen is for the site to detect mobile users and server up an [...]]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s say you want to have a special theme for your WordPress site for mobile users. You don&#8217;t want to use a pre-canned solution or anything third-party, you just want to create and design the theme yourself. So what you need to happen is for the site to detect mobile users and server up an alternate theme instead. Here is how I might do it.</p>
<p><span id="more-1032"></span></p>
<h3>1. Detect for mobiles</h3>
<p>You could do it by <a href="http://css-tricks.com/snippets/javascript/redirect-mobile-devices/">measuring screen size with JavaScript</a>, but that&#8217;s probably not the most solid technique. It can also be done server side with PHP, <a href="http://detectmobilebrowsers.mobi/">check out this project</a> for doing so. Using that code, you could use something like this at the top of your header.php file:</p>
<pre><code>include('mobile_device_detect.php');
$mobile = mobile_device_detect();

if ($mobile==true) {
  // This is a mobile device
} else {
 // This is NOT a mobile device, it's a full-featured browser
}</code></pre>
<h3>2. Install the Theme Switch plugin</h3>
<p>It is available <a href="http://wordpress.org/extend/plugins/nkthemeswitch/">here</a>. This is a sweet plugin for a variety of reasons. I like using it for developing themes right on live sites. We&#8217;ll use it in a different application here though. What the plugin does is create special URLs for your site that activate different themes. </p>
<p>http://your-website.com/?theme=Your_Mobile_Theme</p>
<h3>3. Combine</h3>
<p>Now you can test for mobiles, then redirect to a special theme-switching URL to activate your mobile theme:</p>
<pre><code>include('mobile_device_detect.php');
$mobile = mobile_device_detect();

if ($mobile==true) {
  header( 'Location: http://your-website.com/?theme=Your_Mobile_Theme' ) ;
} else {
 // Do nothing, regular browser.
}</code></pre>
<hr />
<p><small>© 2009 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2009/12/redirect-mobile-users-to-mobile-theme/">Permalink</a> | <a href="http://digwp.com/2009/12/redirect-mobile-users-to-mobile-theme/#comments">23 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2009/12/redirect-mobile-users-to-mobile-theme/&title=Redirect Mobile Users to a Mobile WordPress Theme">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/mobile/" rel="tag">mobile</a>, <a href="http://digwp.com/tag/php/" rel="tag">PHP</a>, <a href="http://digwp.com/tag/theme/" rel="tag">Theme</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2009/12/redirect-mobile-users-to-mobile-theme/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
	</channel>
</rss>

