I'm having problems with redirecting mobile users to the mobile theme.
I have 2 themes: the main theme and it's child - the mobile theme. I use the Theme Switch plug-in and Mobile Detect script to switch to mobile theme. Switching works when the url is called manually and mobile is detected successfully. However, redirecting using both combined with php header is causing me a major headache.
Here's what I'd normally say would work:
include 'script/Mobile_Detect.php';
$detect = new Mobile_Detect();
if ( $detect->isMobile() )
header( 'Location: '.get_home_url().'?theme=Pinnacle+Mobile' );
But I get a redirect loop when I do this. This code is inside the parent theme's header.php and the child theme has it's own version of this file (without any headers).
I figured that wordpress may be calling the header.php script of the parent theme for some reason, even if it should be switched to the mobile theme already and tried to combine this with a cookie like so:
if ( $detect->isMobile() )
{
if ( !( $_COOKIE['redirected'] ) )
{
setcookie( 'redirected', '1', time() + 3600, '/' );
header( 'Location: '.get_home_url().'?theme=Pinnacle+Mobile' );
}
}
But this doesn't work. I always get the full site.