Search by

wpbones / useragent

gfazioli

An useful method to detect the useragent

Package info

github.com/wpbones/useragent

pkg:composer/wpbones/useragent

Statistics

Installs: 629

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 1

1.1.3 2026-10-07 11:35 UTC

README

Latest Stable Version   Total Downloads   License   Monthly Downloads

An useful wrapper for Mobile Detect to detect mobile devices for WP Bones.

Requirements

This package works with a WordPress plugin written with WP Bones framework library.

Installation

You can install third party packages by using:

php bones require wpbones/useragent

I advise to use this command instead of composer require because doing this an automatic renaming will done.

You can use composer to install this package:

composer require wpbones/useragent

You may also to add "wpbones/useragent": "^1.1" in the composer.json file of your plugin:

  "require": {
    "php": ">=8.1",
    "wpbones/wpbones": "^3.0",
    "wpbones/useragent": "^1.1"
  },

and run

composer install

How to

You will be able to use wpbones_user_agent() function to get an instance of Mobile Detect.

if(wpbones_user_agent()->isMobile()) {
  echo "You're by Mobile";
} else {
  echo "You're by Desktop";
}

Sample

// Basic detection.
wpbones_user_agent()->isMobile();
wpbones_user_agent()->isTablet();

// Magic methods.
wpbones_user_agent()->isIphone();
wpbones_user_agent()->isSamsung();
// [...]

// Alternative to magic methods.
wpbones_user_agent()->is('iphone');

// Find the version of component.
wpbones_user_agent()->version('Android');

You may also

// Any mobile device (phones or tablets).
if ( wpbones_user_agent()->isMobile() ) {

}

// Any tablet device.
if( wpbones_user_agent()->isTablet() ){

}

// Exclude tablets.
if( wpbones_user_agent()->isMobile() && !wpbones_user_agent()->isTablet() ){

}

// Check for a specific platform with the help of the magic methods:
if( wpbones_user_agent()->isiOS() ){

}

if( wpbones_user_agent()->isAndroidOS() ){

}

// Alternative method is() for checking specific properties.
// WARNING: this method is in BETA, some keyword properties will change in the future.
wpbones_user_agent()->is('Chrome')
wpbones_user_agent()->is('iOS')
wpbones_user_agent()->is('UCBrowser')
wpbones_user_agent()->is('Opera')
// [...]