【发布时间】:2016-04-06 09:57:07
【问题描述】:
我在我的 Wordpress 上遇到了 wp_redirect 和 wp_is_mobile 函数的一些问题。
我要翻页:
移动表单页面,运行良好:
<?php
if (!is_mobile())
{
wp_redirect( 'MY URL', 301 ); // Redirect to the non-mobile version of the form
exit;
}
?>
// My html form
非移动表单页面,不会重定向: (出于安全原因,我目前删除了重定向脚本)
<?php
if (wp_is_mobile())
{
wp_redirect( 'MY URL', 301 ); // Redirect to mobile version of the form
exit;
}
?>
// My html form
但是...此页面的本地 (WAMP) 版本正在运行。
另外,我尝试制作一个没有任何 HTML 代码的页面,其中重定向在这两种情况下都有效:
<?php
if (is_mobile())
{
wp_redirect( 'MY URL', 301 );
exit;
}
else
{
wp_redirect( 'MY URL', 301 );
exit;
}
?>
感谢您的帮助。
【问题讨论】:
-
你在使用某种缓存插件吗? (例如 W3 总缓存)
-
有WP Super Cache插件,已安装但停用。
-
试试这个:打开它,清除缓存,再次关闭它,测试。
-
它不起作用。在移动版本上,这和以前一样的问题:只显示页面的标题(“当前”页面,重定向不起作用),页面本身保持空白。
标签: php wordpress url-redirection