PHP code example of automattic / jetpack-device-detection

1. Go to this page and download the library: Download automattic/jetpack-device-detection library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

automattic / jetpack-device-detection example snippets


use Automattic\Jetpack\Device_Detection;

$device_info = Device_Detection::get_info();

/**
 * array(
 *  'is_phone'            => (bool) Whether the current device is a mobile phone.
 *  'is_smartphone'       => (bool) Whether the current device is a smartphone.
 *  'is_tablet'           => (bool) Whether the current device is a tablet device.
 *  'is_handheld'         => (bool) Whether the current device is a handheld device.
 *  'is_desktop'          => (bool) Whether the current device is a laptop / desktop device.
 *  'platform'            => (string) Detected platform.
 *  'is_phone_matched_ua' => (string) Matched UA.
 * );
 */

use Automattic\Jetpack\Device_Detection;

$is_phone = Device_Detection::is_phone();

use Automattic\Jetpack\Device_Detection;

$is_smartphone = Device_Detection::is_smartphone();

use Automattic\Jetpack\Device_Detection;

$is_dumbphone = Device_Detection::is_phone() && ! Device_Detection::is_smartphone();

use Automattic\Jetpack\Device_Detection;

$is_tablet = Device_Detection::is_tablet();

use Automattic\Jetpack\Device_Detection;

$is_desktop = Device_Detection::is_desktop();

use Automattic\Jetpack\Device_Detection;

$is_handheld = Device_Detection::is_handheld();