Search by

leowebguy / device-detect

leowebguy

Craft plugin for detecting devices, OS, bots and more

Package info

github.com/leowebguy/devicedetect

Type:craft-plugin

pkg:composer/leowebguy/device-detect

Statistics

Installs: 7 103

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 1

3.1 2024-11-22 15:55 UTC

This package is auto-updated.

Last update: 2026-10-31 13:44:44 UTC


README

Detect devices, OS, bots and more

Wrapper around MobileDetect by @serbanghita

Requirements

This plugin requires Craft CMS ^5.0.0 and PHP ^8.2 || ^8.3 || ^8.4 || ^8.5.

Installation

Open your terminal and go to your Craft project:

composer require leowebguy/device-detect -w && php craft plugin/install device-detect

Usage

The plugin exposes MobileDetect's methods and can be used in your Twig templates:

{{ craft.deviceDetect.isMobile ? 'I am mobile.' : 'I am not mobile.' }}

Devices

{{ craft.deviceDetect.isMobile }}
{{ craft.deviceDetect.isTablet }}
{{ craft.deviceDetect.isiPad }}
{{ craft.deviceDetect.isPhone }}

Operating Systems

{{ craft.deviceDetect.isiOS }}
{{ craft.deviceDetect.isiPadOS }}
{{ craft.deviceDetect.isAndroidOS }}

User Agent

{{ craft.deviceDetect.getUserAgent }}

getUserAgent returns a string, e.g. Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36.

Development

Run quality checks and linters:

# Static analysis
composer phpstan

# Code style
composer pint-test
composer pint