MobileDetect plugin for Craft CMS 3.x
Use Mobile_Detect for detecting mobile devices (including tablets), (*1)
, (*2)
Requirements
This plugin requires Craft CMS 3.0.0-beta.23 or later., (*3)
Installation
To install the plugin, follow these instructions., (*4)
-
Open your terminal and go to your Craft project:, (*5)
cd /path/to/project
-
Then tell Composer to load the plugin:, (*6)
composer require superbig/craft3-mobiledetect
-
In the Control Panel, go to Settings → Plugins and click the “Install” button for MobileDetect., (*7)
MobileDetect Overview
fairly complete wrapper for the Mobile_Detect library by @serbanghita.**, (*8)
Using MobileDetect
The plugin exposes most of Mobile_Detect's methods, and can be used in your Twig:, (*9)
{{ craft.mobileDetect.isMobile ? 'I am mobile.' : 'I am not mobile.' }}
...or as a PHP service:, (*10)
<?php
$isMobile = MobileDetect::$plugin->mobileDetect->isMobile();
Methods/usage
Device detection
isMobile
Detects all mobile devices, both phones and tablets, (*11)
isTablet
isPhone
Mobile OS detection
isiOS
isAndroidOS
isBlackBerryOS
isPalmOS
isSymbianOS
isWindowsMobileOS
isWindowsPhoneOS
Other methods
is(key)
Test for anything, e.g. is('iphone')
, (*12)
match(pattern)
Test using regular expressions, (*13)
version(component)
Get the version of a component, e.g. version('iPhone')
, (*14)
mobileGrade
Get browser grade (e.g. "A"), (*15)
getScriptVersion
Prints the MobileDetect library's version, (*16)
getUserAgent
setUserAgent(userAgent)
getMobileHeaders
getHttpHeaders
setHttpHeaders(httpHeaders)
getCfHeaders
setCfHeaders(cfHeaders)
Brought to you by Superbig, (*17)