Extension:IfMobile

Category:Extensions without an imageCategory:Extensions without a compatibility policyCategory:BSD licensed extensions
MediaWiki extensions manual
IfMobile
Release status: stableCategory:Stable extensions
Implementation Tag Category:Tag extensions
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+Category:Extensions with manual MediaWiki version
License BSD 3-clause "Modified" License
Download Category:Extensions in GitHub version control
#ifmobile
Category:All extensionsCategory:Extensions not in ExtensionJson

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

  • Download and place the file(s) in a directory called IfMobile in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php file:
    wfLoadExtension( 'IfMobile' );
    
  • Yes Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Usage

#ifmobile and #mobileonly parser functions

The IfMobile extension introduces the #ifmobile parser function.

Different HTML attribute for mobile and desktop

<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

Main 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

When need to create different content (similar to MobileDetect).

<div>{{#ifmobile:Content only for mobiles|Content only for desktop}}</div>

Content sent only to desktop

This 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>

See also

Category:Mobile
Category:All extensions Category:BSD licensed extensions Category:Extensions in GitHub version control Category:Extensions not in ExtensionJson Category:Extensions with manual MediaWiki version Category:Extensions without a compatibility policy Category:Extensions without an image Category:Mobile Category:PageRenderingHash extensions Category:ParserFirstCallInit extensions Category:Stable extensions Category:Tag extensions