我正在尝试将http://mobiledetect.net/的PHP版移动检测脚本集成到我的Wordpress安装中。
我使用以下代码来调用和检测移动设备使用
<?php
include 'includes/Mobile_Detect.php';
$detect = new Mobile_Detect;
$isMobile = $detect->isMobile();
if($isMobile) {
//Do a thing;
};
?>
虽然代码确实有效,但我发现页面的加载时间在一致的基础上增加了1-2秒。我已经运行了一些测试,只是include语句本身导致了一个重大的减速。
使用此脚本时这是正常的还是应该有更好的方法来实现它?
答案 0 :(得分:0)
你所包含的脚本可能正在进行一些cpu密集型计算(这可能会减慢它的速度),唯一的方法是找到更好的脚本,或者如果你想要你可以用5-6行的PHP编写自己的代码可以检测用户是否在移动设备上。您可以在此获得更多详细信息:Mobile device detection in PHP
答案 1 :(得分:0)
WordPress有一个内置函数wp_is_mobile()
来检查用户是否使用移动设备。因此,您不必包含和使用unnessacry外部脚本或功能。
答案 2 :(得分:0)
if ( wp_is_mobile() )
{
//Do a thing;
}
else
{
//Do a thing;
}