Making your blog friendly to mobile devices
Jun 22nd, 2006 by Karen
There are a number of different things that you can do to make your blog more friendly to mobile devices. This is something I’ve been working on for a while and there really isn’t one sure fire approach to see why check out this series of articles called “Mobile Web Design”. As a result, there are a couple tactics to making Wordpress render nicely for mobile devices. First, I’d reccomend you create a stylesheet specifically for mobile devices. This means creating a stylesheet for mobile devices that is named mobile.css The mobile.css file will contain the following code:
hr, #footer, .postmetadata { display: none; }
body { font-size: 10px; font-family: 'Lucida Grande', Verdana, Arial, Sans-Serif;}
div { padding: 0; margin: 0 }
p { text-align: justify; padding: 0; margin: 5px 0}
#sidebar ul { margin: 0; padding: 0 }
#sidebar li { margin: 0; padding: 0; list-style-type: none}
#sidebar ul li.largelink ul {margin: 3%;}
a, a:link, a:hover, a:active, a:visited { text-decoration: none; color: #06c }
#header { background-color: #06c; color: white; padding: 3px;}
#header a { background-color: #06c; color: white; padding: 2px;}
#sidebar {
margin-left: 78%;
width: 25%;
}
#content {
float:left;
width:75%;
}
.commentlist li { margin-bottom: 4px }
.commentlist li p { margin-left: 8px;}
Once you’ve created the stylesheet go into your header.php file in your theme and add the following line:
<link media="handheld" type="text/css" rel="stylesheet" />
You can test your mobile stylesheet by using Opera and going to View > Small Screen.
For the mobile devices that don’t read mobile stylesheets, you need to use WAP and WML. More information on WAP and WML can be found at W3C Schools WAP/WML Tutorial. The best option to do this in Wordpress appears to be WP-Wap a plugin which creates a WAP browser compliant version of your site. Install this extension and then visit http://www.yoursite.net/wp-wap.php using Opera or Firefox with the WML extension installed. Make sure the page renders correctly. If it does you can include a redirect in you .htaccess file to redirect all WAP browsers to use the WML version of your homepage. Below are the lines you should put in your .htaccess file.
RewriteCond %{HTTP_ACCEPT} (x-)*(application|text)/(x-)*(vnd[-.])*(wap[-.]|wml)+
RewriteRule ^(index.php)*$ wp-wap.php [L]
One should be able to write a redirect rule that works for all the pages. But my regular expressions and rewrite skills are slightly lacking. I’m still learning about making sites friendly for mobile devices. What I have here are really some beginning steps. My handheld stylesheet has to be refined still. To do that I’m going to be using the tips in Pocket-Sized Design: Taking Your Website to the Small Screen by Elika Etemad, Jorunn D. Newth and 7 Steps to Better Handheld Browsing


Hey very nice post. Well i hope this code works for me and makes my blog better for mobile devices. Thanks in advance :)
This is a pretty tricky topic. There are a few options when it comes to automatically detecting mobile devices and redirecting accordingly. Using .htaccess you sniff the user agent and compare it with a huge list of known (and ever increasing) user agents that correspond with various models of mobile phones, I personally don’t like this approach because of the need to keep it up to date.
I went for the “if accepts wml” approach:
RewriteCond %{HTTP_ACCEPT} text/vnd.wap.wml
RewriteCond %{REQUEST_URI} !^/mobile
RewriteRule ^/?(.*)$ /mobile/ [L]
I couldn’t get your complex regular expression to work for me so just typed it out as text/vnd.wap.wml and it worked. Not sure what the implications are.