wp_is_mobile和wp_redirect无效

时间:2016-04-06 09:57:08

标签: php wordpress url-redirection

我在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;
  }
?>

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

好吧,我所要做的就是重新创建wordpress页面。现在似乎工作正常。不管怎样,谢谢!