0

我在将移动用户重定向到移动主题时遇到问题。

我有 2 个主题:主题和子主题 - 移动主题。我使用 Theme Switch 插件和 Mobile Detect 脚本来切换到移动主题。当手动调用 url 并成功检测到移动设备时,切换工作。但是,使用两者结合 php 标头进行重定向让我非常头疼。

这就是我通常所说的可行的方法:

include 'script/Mobile_Detect.php';
$detect = new Mobile_Detect();

if ( $detect->isMobile() )
    header( 'Location: '.get_home_url().'?theme=Pinnacle+Mobile' );

但是当我这样做时,我会得到一个重定向循环。这段代码在父主题的 header.php 中,子主题有它自己的文件版本(没有任何标题)。

我认为 wordpress 可能出于某种原因调用了父主题的 header.php 脚本,即使它应该已经切换到移动主题并尝试将其与 cookie 结合起来,如下所示:

if ( $detect->isMobile() )
{   
    if ( !( $_COOKIE['redirected'] ) )
    {
        setcookie( 'redirected', '1', time() + 3600, '/' );
        header( 'Location: '.get_home_url().'?theme=Pinnacle+Mobile' ); 
    }
}   

但这不起作用。我总是得到完整的网站。

4

0 回答 0