{"id":18841300,"url":"https://github.com/dmhendricks/detect-remote-device","last_synced_at":"2025-10-14T17:28:49.775Z","repository":{"id":88694296,"uuid":"178738196","full_name":"dmhendricks/detect-remote-device","owner":"dmhendricks","description":"A WordPress plugin that adds additional functions and shortcodes to modify output by device type - mobile, tablet or desktop.","archived":false,"fork":false,"pushed_at":"2019-04-25T19:36:12.000Z","size":362,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-11T21:14:15.094Z","etag":null,"topics":["device-detection","mobile-detection","mobile-web","tablet-detection","wordpress-plugin","wordpress-shortcodes"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dmhendricks.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-03-31T20:23:51.000Z","updated_at":"2023-10-09T00:51:59.000Z","dependencies_parsed_at":null,"dependency_job_id":"c9f4532a-3d38-40a9-8ec3-1c6a942185c6","html_url":"https://github.com/dmhendricks/detect-remote-device","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/dmhendricks/detect-remote-device","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmhendricks%2Fdetect-remote-device","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmhendricks%2Fdetect-remote-device/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmhendricks%2Fdetect-remote-device/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmhendricks%2Fdetect-remote-device/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dmhendricks","download_url":"https://codeload.github.com/dmhendricks/detect-remote-device/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmhendricks%2Fdetect-remote-device/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279020076,"owners_count":26086806,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-14T02:00:06.444Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["device-detection","mobile-detection","mobile-web","tablet-detection","wordpress-plugin","wordpress-shortcodes"],"created_at":"2024-11-08T02:50:44.483Z","updated_at":"2025-10-14T17:28:49.759Z","avatar_url":"https://github.com/dmhendricks.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Author](https://img.shields.io/badge/author-Daniel%20M.%20Hendricks-lightgrey.svg?colorB=9900cc)](https://daniel.hn/?utm_source=github.com\u0026utm_medium=campaign\u0026utm_content=button\u0026utm_campaign=dmhendricks%2Fdetect-remote-device)\n[![GitHub License](https://img.shields.io/badge/license-GPLv2-yellow.svg)](https://raw.githubusercontent.com/dmhendricks/detect-remote-device/master/LICENSE)\n[![BrowserStack Status](https://www.browserstack.com/automate/badge.svg?badge_key=dmFTRkE3MlplYlB6djZyeWVyOU9XVmVEUjBqMjRpc3dXU3Z0QnM5WEhjVT0tLW9FN2tFYWkzZmdId295YjhKRC9aM3c9PQ==--1d6690824fc2a396d950cd61ec80eab2376b0c50)](https://www.browserstack.com/automate/public-build/dmFTRkE3MlplYlB6djZyeWVyOU9XVmVEUjBqMjRpc3dXU3Z0QnM5WEhjVT0tLW9FN2tFYWkzZmdId295YjhKRC9aM3c9PQ==--1d6690824fc2a396d950cd61ec80eab2376b0c50?utm_source=github.com\u0026utm_medium=referral\u0026utm_content=button\u0026utm_campaign=dmhendricks%2Fdetect-remote-device)\n[![Twitter](https://img.shields.io/twitter/url/https/github.com/dmhendricks/detect-remote-device.svg?style=social)](https://twitter.com/danielhendricks)\n\n# Detect Remote Device Plugin for WordPress\n\nThis WordPress plugin is uses the [Agent](https://github.com/jenssegers/agent) and [DeviceDetector](https://github.com/matomo-org/device-detector) PHP libraries to extend `wp_is_mobile()` to (optionally) exclude tablets and add device-specific filters and shortcodes. It was inspired by [Pothi Kalimuthu's](https://www.tinywp.in/?utm_source=github.com\u0026utm_medium=campaign\u0026utm_content=button\u0026utm_campaign=detect-mobile-device) [Mobile Detect](https://wordpress.org/plugins/tinywp-mobile-detect/) plugin.\n\n### Special Thanks\n\nI would like to thank [BrowserStack](http://browserstack.com/?utm_source=github.com\u0026utm_medium=referral\u0026utm_content=link\u0026utm_campaign=dmhendricks%2Fdetect-remote-device) for graciously allowing me to test this plugin's device detection on their platform. If you're looking for seamless application and browser testing  for your projects, give them a try:\n\n[![App and Browser Testing Made Easy](https://f001.backblazeb2.com/file/hendricks/images/github/brands/browserstack/browserstack-logo-350x98.png)](http://browserstack.com/?utm_source=github.com\u0026utm_medium=referral\u0026utm_content=logo\u0026utm_campaign=dmhendricks%2Fdetect-remote-device)\n\n## Requirements\n\n- WordPress 4.7 or higher\n- PHP 5.6 or higher\n\nIf you're not sure if you meet these requirements, the plugin will tell you upon activation.\n\n#### TODO\n\n- [x] Add [OS-specific detection](https://github.com/jenssegers/agent)\n- [ ] Add `[browser_agent_is]` shortcode\n- [x] Add querystring modifiers\n- [x] Add support for getting device type from request headers\n\n### Installation\n\nDownload the distributable ZIP file from the [Releases](https://github.com/dmhendricks/detect-mobile-device/releases) page and install as you normally do for a WordPress plugin.\n\n### Configuration\n\nThe following constants are available to modify behavior. They may be defined in your `wp-config.php`:\n\n- `DMD_DISABLE_GLOBAL_FUNCTIONS` - If defined as true, [global functions](#option-2---global-functions) will not be created.\n- `DMD_DISABLE_SHORTCODES` - If defined as true, shortcodes will not be loaded. Useful if you only want this plugin to solely act as an autoloader for the [Agent](https://github.com/jenssegers/agent) and [DeviceDetector](https://github.com/matomo-org/device-detector) PHP libraries.\n- `DMD_ADD_DEVICE_TYPE_BODY_CLASSES` - Add device type body classes (default: true)\n- `DMD_ADD_PLATFORM_BODY_CLASSES` - Add remote platform/OS body classes (default: false)\n- `DMD_BODY_CLASS_PREFIX` - If defined, modifies the prefix added to device body classes.\n- `DMD_MODIFY_WP_IS_MOBILE` - Modifies WordPress's built-in [`wp_is_mobile()`](https://codex.wordpress.org/Function_Reference/wp_is_mobile) function to return false for tablets.\n\n#### Configuration Examples\n\n```php\ndefine( 'DMD_DISABLE_GLOBAL_FUNCTIONS', true );\ndefine( 'DMD_DISABLE_SHORTCODES', false );\ndefine( 'DMD_ADD_DEVICE_TYPE_BODY_CLASSES', false );\ndefine( 'DMD_ADD_PLATFORM_BODY_CLASSES', true );\ndefine( 'DMD_BODY_CLASS_PREFIX', 'screen' ); // Resulting body classes: screen-mobile, screen-desktop, etc\ndefine( 'DMD_MODIFY_WP_IS_MOBILE', true );\n```\n\n## Usage\n\n### Option 1 - Create MobileDetect Object\n\nIf desired, you can simply instantiate a new instance of [Agent](https://github.com/jenssegers/agent) or [DeviceDetector](https://github.com/matomo-org/device-detector). See each library's documentation for further usage examples.\n\n```php\n$device = new \\Jenssegers\\Agent\\Agent;\n\nif( $device-\u003eisTablet() ) {\n\t// Logic for tablets\n} else if( $device-\u003eisMobile() ) {\n\t// Logic for phones\n} else {\n\t// Logic for desktop\n}\n```\n\n:rotating_light: **NB!** The `isMobile` method returns true for both phones _and_ tablets. In my example above, I check for tablets first, else if not tablet but is mobile, it is a phone. Adjust your logic as desired.\n\n### Option 2 - Global Functions\n\nTo supplement WordPress's built-in [`wp_is_mobile()`](https://codex.wordpress.org/Function_Reference/wp_is_mobile) function (which returns true for phone _and_ tablet), this plugin adds functions to specifically detect phones and tablets:\n\n```php\n// Built-in WordPress function: Do something for phones AND tablets\nif( wp_is_mobile() ) {\n\t// ...\n}\n\n// Custom global functions\nif( device_is_phone() ) {\n\t// ... Phones only\n} else if( device_is_tablet() ) {\n\t// ... Tablets only\n} else if( device_is_desktop() ) {\n\t// ... Desktop only\n} else {\n    // ...\n}\n\n// Get device type as string\necho 'Device type: ' . get_the_device_type(); // Device type: tablet\n```\n\n### Option 3 - Use Shortcodes\n\nThis plugin adds the following shortcodes:\n\n- `[device_is_mobile]` - Display content if **phone** or **tablet**\n- `[device_is_phone]` - Display content if **phone**\n- `[device_is_tablet]` - Display content if **tablet**\n- `[device_is_desktop]` - Display content if **desktop**\n- `[device_is type=\"tablet,phone\"]` - Display content if `type` attribute matches. Multiple types may be separated by comma.\n- `[device_is_not type=\"desktop\"]` - Display content if `type` attribute **does not** match. Multiple types may be separated by comma.\n- **More to come!**\n\n:ok_hand: I realize that these can be consolidated into one shortcode, but I split them out for user semantics. Use them as you wish.\n\n#### Example Shortcode Usage\n\n```\n[device_is_phone]You're using a phone![/device_is_phone]\n\n[device_is type=\"tablet,desktop\"]You're using a tablet or desktop![/device_is]\n\n[device_is_not type=\"phone\"]You're NOT using a phone![/device_is_not]\n```\n\n[![Analytics](https://ga-beacon.appspot.com/UA-126205765-1/dmhendricks/detect-remote-device?flat)](https://ga-beacon.appspot.com/?utm_source=github.com\u0026utm_medium=referral\u0026utm_content=button\u0026utm_campaign=dmhendricks%2Fdetect-remote-device)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmhendricks%2Fdetect-remote-device","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdmhendricks%2Fdetect-remote-device","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmhendricks%2Fdetect-remote-device/lists"}