
As mobile devices, as such as Blackberries or iPhones, are becomming more and more popular, bloggers may want to detect those visitors and redirect them to a mobile version of their blog. Here is a recipe to detect mobile visitors.

As mobile devices, as such as Blackberries or iPhones, are becomming more and more popular, bloggers may want to detect those visitors and redirect them to a mobile version of their blog. Here is a recipe to detect mobile visitors.
To achieve this recipe, you first have to get the code from detectmobilebrowsers.mobi and upload it to your theme directory.
Once done, simply open your header.php file and place the following at the top of the file. Don't forget to edit line 5 according to the page where you'd like to redirect mobile users.
include('mobile_device_detect.php');
$mobile = mobile_device_detect();
if ($mobile==true) {
header( 'Location: http://your-website.com/?theme=Your_Mobile_Theme' ) ;
}
Thanks to Jeff Starr for this very cool idea!
By the way, did you checked out the Headway theme for WordPress? It is pretty amazing. I'll publish a review about it soon at Cats Who Blog.
16 Responses
Nice tips, I will try it later, thanks for sharing.
Funny I found this as I just started doing a similar thing yesterday for one of my clients
Very Cool,, Thanks for sharing.
I think a few friends have tried using my blog on there mobile just to see what it does. It doesn’t work how I want it too. This is a great tip.
Please don’t just redirect to your homepage, since this will throw off mobile users who are linked to a specific post. Many sites do this, and it frustrates me to no end!
Dan Smart over on digwp.com has a much better solution:
function filter_switchTheme($theme)
{
$mobile = mobile_device_detect();
if ($mobile==true)
{
$theme = 'mobile_theme_name';
}
return $theme;
}
And here’s the filters to call:
add_filter('template', filter_switchTheme);
add_filter('option_template', filter_switchTheme);
add_filter('option_stylesheet', filter_switchTheme);
I will try it out on one of my blogs. Thanks
This is a great tip, I’ll definitely give it a try.
Say, does it only work for Blackberries and iPhones or does it also work for other mobile phones with internet?
@Author: nice sharing,, but …
@Trevor: i agreed with you
Even better is the beautiful wptouch. Check it.
thanks i will share it to my readers, of course i will link to you.
I could nt see how this would know the different types of mobile browser but if you look at the detail code on detectmobilebrowsers.mobi it starts to make sense. It has a test for each type of broswer and you can set it to true if you want to treat that browser as mobile. Neat.
Trackbacks: