Skip to content

Instantly share code, notes, and snippets.

@aktaumag
Created June 18, 2020 18:03
Show Gist options
  • Save aktaumag/df12fd39bd940a106e4669ff6c521c5f to your computer and use it in GitHub Desktop.
Save aktaumag/df12fd39bd940a106e4669ff6c521c5f to your computer and use it in GitHub Desktop.
Убрать из мобильной версии всё, что для десктопной
@aktaumag
Copy link
Author

aktaumag commented Jun 18, 2020

https://github.com/serbanghita/Mobile-Detect
Скачиваем файл Mobile_Detect.php и добавляем себе его в кукой-нибудь folder/path

В нужном месте (желательно в самом верху PHP файла, прописываем:

require_once '/folder/path/Mobile_Detect.php';
$detect = new Mobile_Detect;

А там где нужно разделить мобильный код от десктопного применяем такой код

if ($detect->isMobile()) {
    // Это мобильное устройство или планшет
}

if( $detect->isMobile() && !$detect->isTablet() ){
    // Это мобильное устройство
}

if($detect->isTablet()){
    // Это планшет
}

if (!$detect->isMobile()) {
    // Это десктоп
}

А ещё можно определить, что это браузер Chome, чтобы применить какие-то плюхи не поддерживаемые другими браузерами

$detect->is('Chrome')

@aktaumag
Copy link
Author

CMS Bitrix
Уже встроено

use \Bitrix\Conversion\Internals\MobileDetect;
$detect = new MobileDetect;
if($detect->isMobile())
{
    // мобильное устройство
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment