Skip to content

Instantly share code, notes, and snippets.

@jaredatch
Created May 13, 2014 20:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaredatch/d9230215ed8d8beca2c3 to your computer and use it in GitHub Desktop.
Save jaredatch/d9230215ed8d8beca2c3 to your computer and use it in GitHub Desktop.
Mobile detection for NGINX Synthesis accounts
<?php
/**
* Basic mobile detection for Synthesis accounts with NGINX caching.
*
* @since 1.0.0
* @return boolean
*/
function ja_is_mobile() {
if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
return false;
$agent = strtolower( $_SERVER['HTTP_USER_AGENT'] );
$mobile = false;
$mobile_devices = array( 'android', 'iphone', 'ipod', 'winphone8' );
$tablet_devices = array( 'tablet', 'tablet-android' );
// Check for mobile device user agent
foreach ( $mobile_devices as $device ) {
if ( false !== strrpos( $agent , $device ) ) {
$mobile = true;
}
}
// Check for tablet user agent part, which will override the first check
foreach ( $tablet_devices as $device ) {
if ( false !== strrpos( $agent , $device ) ) {
$mobile = false;
}
}
return $mobile;
}
/**
* Load mobile changes and tweaks if needed.
*/
if ( ja_is_mobile() ) {
require_once( CHILD_DIR . '/inc/mobile.php' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment