我是新的wordpress插件开发,但无论如何,我已经开发了两个短码,即[MY_SHORTCODE]和[MY_SHORTCODE_MOBILE],都工作得很好,但现在我想做一个增强,那就是,我想写一个新的短码,其中detect the device,如果检测到的设备是移动的,那么我想调用短码[MY_SHORTCODE_MOBILE],否则我想调用[MY_SHORTCODE]。我该怎么做呢?请帮帮我。
发布于 2013-02-06 18:53:11
我知道你的问题是你想在浏览器或移动设备上运行短代码。
下载mobile detect代码的php文件,并将代码放在下面你想在哪里运行短代码
<?php
$useragent=$_SERVER['HTTP_USER_AGENT'];
if(preg_match('/copy paste mobile detect code here from detectmobilebrowser.php',substr($useragent,0,4)))
{
//header('Location: http://detectmobilebrowser.com/mobile');
// that code run for mobile device
echo do_shortcode("[MY_SHORTCODE_MOBILE]");
}
else{
// that code run for browser
echo do_shortcode("[MY_SHORTCODE]");
}
?> 发布于 2013-02-06 12:22:03
您可以通过插件Mobile Detector来完成此操作
或者,如果您想创建自己的库,可以从使用移动检测库(PHP)开始
mobile-detect
https://stackoverflow.com/questions/14721467
复制相似问题