我们在制作响应式主题时会根据不同的设备推送不同的内容,这样有效的避免了移动设备对主机带宽压力,在需要什么样的内容接受什么的样式及内容。
前言(head部分添加):
直接贴代码:
/** * *手机移动设备识别函数 * **/ function is_mobile() { $user_agent = $_SERVER['HTTP_USER_AGENT']; $mobile_browser = Array( "mqqbrowser", //手机QQ浏览器 "opera mobi", //手机opera "juc","iuc",//uc浏览器 "fennec","ios","applewebKit/420","applewebkit/525","applewebkit/532","ipad","iphone","ipaq","ipod", "iemobile", "windows ce",//windows phone "240x320","480x640","acer","android","anywhereyougo.com","asus","audio","blackberry", "blazer","coolpad" ,"dopod", "etouch", "hitachi","htc","huawei", "jbrowser", "lenovo", "lg","lg-","lge-","lge", "mobi","moto","nokia","phone","samsung","sony", "symbian","tablet","tianyu","wap","xda","xde","zte" ); $is_mobile = false; foreach ($mobile_browser as $device) { if (stristr($user_agent, $device)) { $is_mobile = true; break; } } return $is_mobile; }
以上代码直接写到functions.php
//显示手机移动端内容 //非手机移动端内容
正文到此结束
版权声明:本文基于《知识共享署名-相同方式共享 3.0 中国大陆许可协议》发布,转载请遵循本协议!!
LEAVE A REPLY