wp_is_mobile

Test if the current browser runs on a mobile device (smart phone, tablet, etc.).

Description

wp_is_mobile(); 

Usage

  1. if ( !function_exists( 'wp_is_mobile' ) ) { 
  2. require_once ABSPATH . WPINC . '/vars.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wp_is_mobile(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/vars.php  
  1. function wp_is_mobile() { 
  2. if ( empty($_SERVER['HTTP_USER_AGENT']) ) { 
  3. $is_mobile = false; 
  4. } elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false // many mobile devices (all iPhone, iPad, etc.) 
  5. || strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false 
  6. || strpos($_SERVER['HTTP_USER_AGENT'], 'Silk/') !== false 
  7. || strpos($_SERVER['HTTP_USER_AGENT'], 'Kindle') !== false 
  8. || strpos($_SERVER['HTTP_USER_AGENT'], 'BlackBerry') !== false 
  9. || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== false 
  10. || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mobi') !== false ) { 
  11. $is_mobile = true; 
  12. } else { 
  13. $is_mobile = false; 
  14.  
  15. return $is_mobile;