Answer the question
In order to leave comments, you need to log in
How to implement a redirect to the mobile version of the site in Wordpress?
Good day, dear community. I'm here in an attempt to solve my non-trivial task - I have reached a dead end. In general, I adapted my site for mobile devices and added a switch between versions, of this kind.
/*-- Переключение на мобильную версию сайта ссылкой --*/
session_start(); // начинаем сессию
if (isset($_REQUEST['version'])) { // перехватываем линк
$_SESSION['version'] = $_REQUEST['version'];
}
function mobileview($on){ // создаем удобную функцию
$on=$_SESSION['version'] == 'mobile';
return $on;
}
if (wp_is_mobile()) {
setcookie('mobile', '1', time()+9999999, '/', home_url());
header('Location:' . home_url() . '/?version=mobile');
}
if ($_COOKIE['mobile'] != '1') {
if ($_SESSION['version'] == 'desktop') {
setcookie('mobile', '2', time()+9999999, '/', home_url());
header('Location:' . home_url());
}
}
Answer the question
In order to leave comments, you need to log in
The problem is nevertheless solved =) As expected, the solution turned out to be outrageously simple.
if( !isset($_SESSION['version']) && wp_is_mobile()) {
wp_redirect( '/?version=mobile' );
exit;
}
I am a mobile device user, I beg you: do not make a mobile version of the site! She is not needed. Already today there are mobile devices with a resolution MORE than in work computers. And waiting for the mobile version to load first, and then the full version of the site in the conditions of greedily slow cellular networks is such a torment that you can’t pick up normal words right away (hello to the big three!). Thank you very much for your understanding!
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question