wp_is_mobile

The timeline below displays how wordpress function wp_is_mobile has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.5

/**
 * Test if the current browser runs on a mobile device (smart phone, tablet, etc.).
 *
 * @since 3.4.0
 * @since 6.4.0 Added checking for the Sec-CH-UA-Mobile request header.
 *
 * @return bool
 */
function wp_is_mobile()
{
    if (isset($_SERVER['HTTP_SEC_CH_UA_MOBILE'])) {
        // This is the `Sec-CH-UA-Mobile` user agent client hint HTTP request header.
        // See <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-CH-UA-Mobile>.
        $is_mobile = '?1' === $_SERVER['HTTP_SEC_CH_UA_MOBILE'];
    } elseif (empty($_SERVER['HTTP_USER_AGENT'])) {
        $is_mobile = false;
    } elseif (str_contains($_SERVER['HTTP_USER_AGENT'], 'Mobile') || str_contains($_SERVER['HTTP_USER_AGENT'], 'Android') || str_contains($_SERVER['HTTP_USER_AGENT'], 'Silk/') || str_contains($_SERVER['HTTP_USER_AGENT'], 'Kindle') || str_contains($_SERVER['HTTP_USER_AGENT'], 'BlackBerry') || str_contains($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') || str_contains($_SERVER['HTTP_USER_AGENT'], 'Opera Mobi')) {
        $is_mobile = true;
    } else {
        $is_mobile = false;
    }
    /**
     * Filters whether the request should be treated as coming from a mobile device or not.
     *
     * @since 4.9.0
     *
     * @param bool $is_mobile Whether the request is from a mobile device or not.
     */
    return apply_filters('wp_is_mobile', $is_mobile);
}

WordPress Version: 6.4

/**
 * Test if the current browser runs on a mobile device (smart phone, tablet, etc.)
 *
 * @since 3.4.0
 * @since 6.4.0 Added checking for the Sec-CH-UA-Mobile request header.
 *
 * @return bool
 */
function wp_is_mobile()
{
    if (isset($_SERVER['HTTP_SEC_CH_UA_MOBILE'])) {
        // This is the `Sec-CH-UA-Mobile` user agent client hint HTTP request header.
        // See <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-CH-UA-Mobile>.
        $is_mobile = '?1' === $_SERVER['HTTP_SEC_CH_UA_MOBILE'];
    } elseif (empty($_SERVER['HTTP_USER_AGENT'])) {
        $is_mobile = false;
    } elseif (str_contains($_SERVER['HTTP_USER_AGENT'], 'Mobile') || str_contains($_SERVER['HTTP_USER_AGENT'], 'Android') || str_contains($_SERVER['HTTP_USER_AGENT'], 'Silk/') || str_contains($_SERVER['HTTP_USER_AGENT'], 'Kindle') || str_contains($_SERVER['HTTP_USER_AGENT'], 'BlackBerry') || str_contains($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') || str_contains($_SERVER['HTTP_USER_AGENT'], 'Opera Mobi')) {
        $is_mobile = true;
    } else {
        $is_mobile = false;
    }
    /**
     * Filters whether the request should be treated as coming from a mobile device or not.
     *
     * @since 4.9.0
     *
     * @param bool $is_mobile Whether the request is from a mobile device or not.
     */
    return apply_filters('wp_is_mobile', $is_mobile);
}

WordPress Version: 6.3

/**
 * Test if the current browser runs on a mobile device (smart phone, tablet, etc.)
 *
 * @since 3.4.0
 *
 * @return bool
 */
function wp_is_mobile()
{
    if (empty($_SERVER['HTTP_USER_AGENT'])) {
        $is_mobile = false;
    } elseif (str_contains($_SERVER['HTTP_USER_AGENT'], 'Mobile') || str_contains($_SERVER['HTTP_USER_AGENT'], 'Android') || str_contains($_SERVER['HTTP_USER_AGENT'], 'Silk/') || str_contains($_SERVER['HTTP_USER_AGENT'], 'Kindle') || str_contains($_SERVER['HTTP_USER_AGENT'], 'BlackBerry') || str_contains($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') || str_contains($_SERVER['HTTP_USER_AGENT'], 'Opera Mobi')) {
        $is_mobile = true;
    } else {
        $is_mobile = false;
    }
    /**
     * Filters whether the request should be treated as coming from a mobile device or not.
     *
     * @since 4.9.0
     *
     * @param bool $is_mobile Whether the request is from a mobile device or not.
     */
    return apply_filters('wp_is_mobile', $is_mobile);
}

WordPress Version: 5.1

/**
 * Test if the current browser runs on a mobile device (smart phone, tablet, etc.)
 *
 * @since 3.4.0
 *
 * @return bool
 */
function wp_is_mobile()
{
    if (empty($_SERVER['HTTP_USER_AGENT'])) {
        $is_mobile = false;
    } elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Silk/') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Kindle') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'BlackBerry') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mobi') !== false) {
        $is_mobile = true;
    } else {
        $is_mobile = false;
    }
    /**
     * Filters whether the request should be treated as coming from a mobile device or not.
     *
     * @since 4.9.0
     *
     * @param bool $is_mobile Whether the request is from a mobile device or not.
     */
    return apply_filters('wp_is_mobile', $is_mobile);
}

WordPress Version: 4.9

/**
 * Test if the current browser runs on a mobile device (smart phone, tablet, etc.)
 *
 * @since 3.4.0
 * 
 * @return bool
 */
function wp_is_mobile()
{
    if (empty($_SERVER['HTTP_USER_AGENT'])) {
        $is_mobile = false;
    } elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Silk/') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Kindle') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'BlackBerry') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mobi') !== false) {
        $is_mobile = true;
    } else {
        $is_mobile = false;
    }
    /**
     * Filters whether the request should be treated as coming from a mobile device or not.
     *
     * @since 4.9.0
     *
     * @param bool $is_mobile Whether the request is from a mobile device or not.
     */
    return apply_filters('wp_is_mobile', $is_mobile);
}

WordPress Version: 4.8

/**
 * Test if the current browser runs on a mobile device (smart phone, tablet, etc.)
 *
 * @since 3.4.0
 * 
 * @return bool
 */
function wp_is_mobile()
{
    if (empty($_SERVER['HTTP_USER_AGENT'])) {
        $is_mobile = false;
    } elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Silk/') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Kindle') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'BlackBerry') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mobi') !== false) {
        $is_mobile = true;
    } else {
        $is_mobile = false;
    }
    return $is_mobile;
}

WordPress Version: 4.5

/**
 * Test if the current browser runs on a mobile device (smart phone, tablet, etc.)
 *
 * @return bool
 */
function wp_is_mobile()
{
    if (empty($_SERVER['HTTP_USER_AGENT'])) {
        $is_mobile = false;
    } elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Silk/') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Kindle') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'BlackBerry') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mobi') !== false) {
        $is_mobile = true;
    } else {
        $is_mobile = false;
    }
    return $is_mobile;
}

WordPress Version: 4.3

/**
 * Test if the current browser runs on a mobile device (smart phone, tablet, etc.)
 *
 * @staticvar bool $is_mobile
 *
 * @return bool
 */
function wp_is_mobile()
{
    static $is_mobile = null;
    if (isset($is_mobile)) {
        return $is_mobile;
    }
    if (empty($_SERVER['HTTP_USER_AGENT'])) {
        $is_mobile = false;
    } elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Silk/') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Kindle') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'BlackBerry') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mobi') !== false) {
        $is_mobile = true;
    } else {
        $is_mobile = false;
    }
    return $is_mobile;
}

WordPress Version: 3.7

/**
 * Test if the current browser runs on a mobile device (smart phone, tablet, etc.)
 *
 * @return bool true|false
 */
function wp_is_mobile()
{
    static $is_mobile;
    if (isset($is_mobile)) {
        return $is_mobile;
    }
    if (empty($_SERVER['HTTP_USER_AGENT'])) {
        $is_mobile = false;
    } elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Silk/') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Kindle') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'BlackBerry') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mobi') !== false) {
        $is_mobile = true;
    } else {
        $is_mobile = false;
    }
    return $is_mobile;
}