Extension:IfMobile
![]() Release status: stable |
|
---|---|
Implementation | Tag |
Description | Detects mobile devices and allows to control HTML and template arguments specific for mobile devices and desktops. |
Author(s) | Stano Lacko |
Maintainer(s) | Stano Lacko |
Latest version | 0.2.1 (2025-02-17) |
MediaWiki | 1.39+ |
License | BSD 3-clause "Modified" License |
Download | Download release Note: |
#ifmobile |
|
The IfMobile extension detects mobile devices using PHP's HTTP_USER_AGENT
.
The extension introduces a function called wfMobileDetect()
, which returns true when a mobile device is detected, and false otherwise.
The extention introduces parser function #ifmobile
which allow users to control HTML content (attributes' values) and Template arguments for mobile devices and desktop devices.
It creates also separated cache for mobile and desktop devices.
It is very helpful, when it is very complicated to made two outputs one for mobile, one for desktop and show proper output on visitors device.
IfMobile check visitor device and shows output with specific html styles, table colspan/rowspan, etc depends on device type.
Installation
edit- Download and place the file(s) in a directory called
IfMobile
in yourextensions/
folder. - Add the following code at the bottom of your LocalSettings.php file:
wfLoadExtension( 'IfMobile' );
- Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.
Usage
edit#ifmobile and #mobileonly parser functions
editThe IfMobile extension introduces the #ifmobile
parser function.
Different HTML attribute for mobile and desktop
edit<div style="background-color:{{#ifmobile:color for mobile devices|color for desktop devices}}">Content</div>
This solution not need to create content twice as in MobileDetect extension. Because both types of devices received different HTML output (mobile with different color as desktop).
Different Template arguments for mobile and desktop
editMain advantage is to control arguments send to templates and also arguments in templates themself.
{{Feature|name=City|variant=image|size={{#ifmobile:x20px|x15px}}|text=In city with blahblahblah}}
Different content for mobile and desktop
editWhen need to create different content (similar to MobileDetect).
<div>{{#ifmobile:Content only for mobiles|Content only for desktop}}</div>
Content sent only to desktop
editThis solution decrease HTML file sent to mobile devices, because it not contains hidden desktop content as in MobileDevice extension.
<div>{{#ifmobile:|Content only for desktop}}</div>