WordPress wp_is_mobile()函数不起作用 [英] Wordpress wp_is_mobile() function not working
问题描述
我在Wordpress上有一个插件,当用户使用手机时我想阻止它.在我的functions.php中,添加了以下行:
I have a plugin on my Wordpress that I want to block when a user is on mobile. In my functions.php I added the line:
if (wp_is_mobile())
{
wp_dequeue_script('flare');
wp_deregister_script('flare');
}
不幸的是,这使脚本无法同时为移动和桌面用户加载.因此,如果它们在移动设备上,我需要找出一种方法来卸载此脚本.
Unfortunately, this made the script not load for both mobile and desktop users. So I need to figure out a way to make this script unload if they are on mobile.
我在帖子模板中使用了类似的功能,用于在帖子底部添加常规共享按钮(如果它们在移动设备上的话)-但这也不起作用.它为移动和台式机用户添加了共享按钮.
I used a similar function inside my post-template, for adding regular share buttons at the bottom of the post if they were on mobile - but this also didn't work. It added the share buttons for both mobile and desktop users.
任何帮助将不胜感激!
推荐答案
尝试一下...
if ( strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false
|| strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false
|| strpos($_SERVER['HTTP_USER_AGENT'], 'Silk/') !== false
|| strpos($_SERVER['HTTP_USER_AGENT'], 'Kindle') !== false
|| strpos($_SERVER['HTTP_USER_AGENT'], 'BlackBerry') !== false
|| strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== false
|| strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mobi') !== false ) {
//Mobile browser do stuff here
} else {
//Do stuff here
}
这篇关于WordPress wp_is_mobile()函数不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!