More Fun with User Agent Strings and WordPress Conditional Tags for Mobile Devices

Originally Posted on February 14, 2013Last Updated on February 20, 2013

I’ve written before on how to create simple conditional tags for WordPress such as is_iphone() & is_ipad(). With Android gadgets ever climbing the plethora of charts claiming browser market share, though, I thought it might be nice to include those guys in the mix. Maybe something will come of this Google company after all.

Thusly, I present to you the following for your functions.php file, a plethora of WordPress functions to add new conditional tags for iOS devices as well as Android, and some fun combos.

WordPress’ wp_is_mobile() considers iPad the same as the iPhone which isn’t always ideal. Desktop sites can look great on iPad where as iPhone is smaller. Ideally wp_is_mobile() would not include tablets and a new function would be used for tablets. Or attributes added to filter out certain devices.

The code provided above is a much better alternative as it gives the developer control over devices.