从桌面设备重定向访问移动网站的用户



我创建了2个不同的网站,一个用于移动设备,一个用于使用Wordpress的桌面!我使用了一个名为等效移动重定向的插件,以便在移动用户访问桌面网站时将他们重定向到移动网站!现在我需要反之亦然,我似乎找不到有效的方法!有什么想法吗?

你可以用javascript检查:

var isMobile = {
Android: function() {
return navigator.userAgent.match(/Android/i);
},
BlackBerry: function() {
return navigator.userAgent.match(/BlackBerry/i);
},
iOS: function() {
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
},
Opera: function() {
return navigator.userAgent.match(/Opera Mini/i);
},
Windows: function() {
return navigator.userAgent.match(/IEMobile/i);
},
any: function() {
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
}
};
if(isMobile.any()){
// Mobile!
} else {
// Desktop
}

如果你不想使用 Javascript,请查看此代码。您可以使用WordPress的检测移动功能重定向,如果访问者在桌面浏览器上。

if(!wp_is_mobile()){
// If not using mobile
wp_redirect( "https://your_desktop_site.com");
exit;
}

您可以将此代码添加到主题的函数.php文件中,它将起作用。

最新更新