Post Pic

How to detect mobile visitors on your WordPress blog

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.

Related Posts

Related Posts

No related posts.

3 Responses

May 05 2012 22:30

This is putting my website into an infinite loop.

I have uploaded my mobile theme to WordPress theme directory and I added its name in the code as:
http://website.com/?theme=My_Mobile_Theme

What am I doing wrong here? Please help me out!

May 08 2012 12:28

Hi there,

Thank you for the link to my http://detectmobilebrowsers.mobi/ website, I just wanted to say here it’s appreciated and also to let you know that I’ve just released the latest version of the webiste.

Thanks

Andy

Aug 12 2012 09:16

This blog is making everything easy for me. Whenever, I get any wordpress problem. I come here and search. I always get the best solutions here. Your short and simple tricks are the best. Thanks again for this post!

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required

WP Theme of the week

Sponsored Likebox