This is a lightweight mobile detection module based on the Mobile_Detect.php library, which can be obtained from the GitHub repository.

This module is designed to assist developers using mobile-first and responsive design techniques who also need to apply slight variations for mobile and tablet users.

An example use case would be showing or hiding a block based on the type of device.


Installation

Use composer to install the module and its dependencies.
composer require 'drupal/mobile_detect:^4.0'

What does it do?

This module allows you to configure block visibility conditions based on device type or platform via the Drupal user interface.

The Mobile Detect Status block is included for testing purposes.

You can also use it programmatically in your PHP code or within Twig templates.

PHP

$md = \Drupal::service('mobile_detect');
$is_mobile = $md->isMobile();
$is_tablet = $md->isTablet();

Twig Extensions

{% if is_mobile() %}
{% if is_tablet() %}
{% if is_device('iPhone') %}
{% if is_ios() %}
{% if is_android_os() %}

There are not major upgrades so moving from 3.0.0 to 4.0.0 is safe.

Project information

Releases

4.0.0 Stable release covered by the Drupal Security Team released 18 May 2025
Works with Drupal: ^10 || ^11

Drupal 11 and Mobile Detect 4.8.09 support

Install:

Development version: 4.0.x-dev updated 13 Apr 2025 at 14:41 UTC

3.0.6 Stable release covered by the Drupal Security Team released 14 December 2023
Works with Drupal: ^8 || ^9 || ^10
Install:

Development version: 3.0.x-dev updated 21 Feb 2024 at 17:49 UTC