How do I transform this code to work in WordPress? I need to use the if statements in the theme template files:
function iOSDetect() {
global $device;
$browser = $_SERVER['HTTP_USER_AGENT'];
if(strstr($browser, 'iPhone') || strstr($browser, 'iPod')) {
$device = 'iPhone';
} else { $device = 'default'; }
}
iOSDetect();
if($device == 'default') {
// Do something
} else { /* Do something else */ }
try it this way:
Or, you can use a better way:
and then, use it this way:
It looks like you’ll just call the function once, so it’s not like you really need it to be a function.
Also, that looks like kind of a global vars abuse to me.
BTW, if the thing to do is just one (loading different css/js files) you can simplify: