Use Mobile_Detect for detecting mobile devices (including tablets).
Overview
A wrapper for the Mobile_Detect library (v4) by @serbanghita.
Usage
Twig
{# Device detection #}
{{ craft.mobileDetect.isMobile ? 'I am mobile.' : 'I am not mobile.' }}
{{ craft.mobileDetect.isTablet ? 'Tablet' : 'Not a tablet' }}
{{ craft.mobileDetect.isPhone ? 'Phone' : 'Not a phone' }}
{# OS detection — magic methods #}
{% if craft.mobileDetect.isiOS %}
<p>Welcome, iOS user!</p>
{% elseif craft.mobileDetect.isAndroidOS %}
<p>Welcome, Android user!</p>
{% endif %}
{# Browser detection — magic methods #}
{% if craft.mobileDetect.isChrome %}
<p>You're using Chrome</p>
{% elseif craft.mobileDetect.isSafari %}
<p>You're using Safari</p>
{% endif %}
{# Generic rule matching #}
{{ craft.mobileDetect.is('iOS') }}
{{ craft.mobileDetect.is('WindowsPhoneOS') }}
{{ craft.mobileDetect.is('Firefox') }}
PHP
$service = \superbig\mobiledetect\MobileDetect::getInstance()->mobileDetectService;
$isMobile = $service->isMobile();
$isIOS = $service->is('iOS');
Methods
Device detection
| Method | Description |
|---|---|
isMobile | Returns true for any mobile device (including tablets) |
isTablet | Returns true for tablets only |
isPhone | Returns true for phones only (mobile but not tablet) |
OS & browser detection (magic methods)
Any is* call is forwarded to the library's rule matching. These work in both Twig and PHP:
| Method | Description |
|---|---|
isiOS | iOS devices |
isAndroidOS | Android devices |
isBlackBerryOS | BlackBerry devices |
isWindowsMobileOS | Windows Mobile devices |
isWindowsPhoneOS | Windows Phone devices |
isChrome | Chrome browser |
isSafari | Safari browser |
isFirefox | Firefox browser |
is* | Any rule the library supports — see Mobile_Detect docs |
Rule-based detection
| Method | Description |
|---|---|
is(key) | Test any rule by name, e.g. is('iOS'), is('AndroidOS'), is('Chrome') |
match(pattern) | Test using a regular expression against the user agent |
version(component) | Get the version of a component, e.g. version('Android') |
Utility methods
| Method | Description |
|---|---|
getVersion | Returns the Mobile_Detect library version |
getUserAgent | Get the current user agent string |
Installation Instructions
To install this plugin, copy the command above to your terminal.
Reviews
This plugin doesn't have any reviews.
Active Installs
631
License
Craft
Last release
February 13, 2026
Activity (30 days)
3
Closed Issues
0
Open Issues
1
Merged PRs
0
Open PRs