On this page
Mobile detect - drupal 8
Last updated on
30 April 2025
drupal 8 module for detect mobile devices.
This is a lightweight mobile detection based on the Mobile_Detect.php library.
github link: mobile_detect
PHP examples
Check type device
$mobileDetector = \Drupal::service('krs.mobile_detect');
$mobileDetector->isMobile();
$mobileDetector->isTablet()
Check phone
is[iPhone|HTC|Nexus|Dell|Motorola|Samsung|Sony|Asus|Palm|Vertu|GenericPhone]
$mobileDetector->isIphone();
$mobileDetector->isHTC();
Check tablet
is[BlackBerryTablet|iPad|Kindle|SamsungTablet|HTCtablet|MotorolaTablet|AsusTablet|NookTablet|AcerTablet| YarvikTablet|GenericTablet]
$mobileDetector->isIpad();
$mobileDetector->isMotorolaTablet();
Check mobile OS
is[AndroidOS|BlackBerryOS|PalmOS|SymbianOS|WindowsMobileOS|iOS|badaOS]
$mobileDetector->isAndroidOS();
$mobileDetector->isIOS();
Twig Helper
{% if is_mobile() %}
{% if is_tablet() %}
{% if is_device('iphone') %}
{% if is_ios() %}
{% if is_android_os() %}
Help improve this page
Page status: Not set
You can:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion