
MobileDetect
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).
Features
- Four output methods: Fenom modifier, Fenom blocks, snippet, HTML tags
- Forced mode: GET parameter
?browser=mobile - Cookie: remembers the user's choice
- Version switcher:
tplMobileDetectSwitchchunk from the package - PHP API:
MobileDetectservice for plugins and snippets
Requirements
| 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.
Installation
- Install via Extras → Installer (modstore.pro, free)
- Ensure plugin MobileDetect is enabled (
md_disable_plugin = No) - Manage → Clear cache
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.
Output methods
| # | 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.
Quick links
| 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 |
History
Originally written by Vasily Naumkin as a tutorial on bezumkin.ru. Current version 2.1.0-pl is maintained at modx-pro/MobileDetect.
