
MobileDetect
Device type detection in MODX and different content on a single page


The component detects the visitor's device type (desktop, tablet, mobile) and lets you output different content on one MODX page.
Built on mobiledetect/mobiledetectlib ^4.11 (Detection\MobileDetect).
?browser=mobiletplMobileDetectSwitch chunk from the packageMobileDetect service for plugins and snippets| Requirement | Version |
|---|---|
| MODX Revolution | 2.8+ or 3.x |
| PHP | 8.2+ |
| pdoTools | optional; required for Fenom blocks and the | mobiledetect modifier |
Detection uses User-Agent and HTTP headers. "Desktop site" mode in a mobile browser may return incorrect results.
md_disable_plugin = No)After install:
| Element | Purpose |
|---|---|
| Plugin MobileDetect | HTML tags, Fenom, mobiledetect.device placeholder |
| Snippet MobileDetect | Conditional output via :is/:then |
| Chunk tplMobileDetectSwitch | Desktop / tablet / mobile / auto links |
The mobiledetectlib library is bundled in transport. Do not run composer install on the server.
| # | Method | When to use |
|---|---|---|
| 1 | Fenom | mobiledetect | Best with pdoTools: code in false branches does not run |
| 2 | Fenom blocks {mobile}, {phone}, … | Readable markup in Fenom templates |
| 3 | Snippet [[!MobileDetect]] | Without Fenom, in any MODX context |
| 4 | HTML tags <standard>, <tablet>, <mobile> | Cache-friendly; MODX tags inside blocks parse before filtering |
Details: Integration.
| Section | Description |
|---|---|
| Quick start | First integration in 5 minutes |
| System settings | md_* keys |
| MobileDetect snippet | &input parameter |
| Integration | Fenom, HTML tags, PHP API |
| Troubleshooting | Cache, pdoTools, upgrade from 2.0.x |
Originally written by Vasily Naumkin as a tutorial on bezumkin.ru. Current version 2.1.0-pl is maintained at modx-pro/MobileDetect.