Title: wp_is_mobile
Published: April 25, 2014
Last modified: February 24, 2026

---

# wp_is_mobile(): bool

## In this article

 * [Return](https://developer.wordpress.org/reference/functions/wp_is_mobile/?output_format=md#return)
 * [More Information](https://developer.wordpress.org/reference/functions/wp_is_mobile/?output_format=md#more-information)
 * [Source](https://developer.wordpress.org/reference/functions/wp_is_mobile/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/wp_is_mobile/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/wp_is_mobile/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_is_mobile/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_is_mobile/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/wp_is_mobile/?output_format=md#wp--skip-link--target)

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

## 󠀁[Return](https://developer.wordpress.org/reference/functions/wp_is_mobile/?output_format=md#return)󠁿

 bool

## 󠀁[More Information](https://developer.wordpress.org/reference/functions/wp_is_mobile/?output_format=md#more-information)󠁿

This Conditional Tag checks if the user is visiting using a mobile device. This 
is a boolean function, meaning it returns either TRUE or FALSE. It works through
the detection of the browser user agent string ($_SERVER[‘HTTP_USER_AGENT’])

Do not think of this function as a way of detecting phones. Its purpose is not detecting
screen width, but rather adjusting for the potentially limited resources of mobile
devices. A mobile device may have less CPU power, memory and/or bandwidth available.
This function will return true for a tablet, as it too is considered a mobile device.
It is **not** a substitute for CSS media queries or styling per platform.

One way that this function could be used in a theme is to produce a very light version
of the site that does not have the large payload of the desktop site. Note that 
both the desktop and the mobile versions of the page will still need to be responsive,
as an older portrait phone will have a significantly different width than a modern
iPad in landscape. [wp_is_mobile()](https://developer.wordpress.org/reference/functions/wp_is_mobile/)
will be true for both. Similarly a desktop browser window may not be displayed at
full width. Essentially this approach may double the amount of work you will need
to put into the theme. Yet for a tightly optimized theme or a unique mobile experience,
it may be essential. It also means that a proper theme may have at least three different
responsive design specs: Desktop, Mobile and AMP.

Additionally, care must be taken when using this function in a public theme. If 
your theme works differently for mobile devices and desktop devices, any page caching
solution used MUST keep separate mobile/non-mobile buckets. Many caching solutions
do not do this or charge for this feature. Even the most detailed read me file may
not be able to adequately explain these details

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_is_mobile/?output_format=md#source)󠁿

    ```php
    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' ) // Many mobile devices (all iPhone, iPad, etc.)
    		|| 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 );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/vars.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/vars.php#L163)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/vars.php#L163-L190)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/wp_is_mobile/?output_format=md#hooks)󠁿

 [apply_filters( ‘wp_is_mobile’, bool $is_mobile )](https://developer.wordpress.org/reference/hooks/wp_is_mobile/)

Filters whether the request should be treated as coming from a mobile device or 
not.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_is_mobile/?output_format=md#related)󠁿

| Uses | Description | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  |

| Used by | Description | 
| [WP_Customize_Manager::customize_pane_settings()](https://developer.wordpress.org/reference/classes/wp_customize_manager/customize_pane_settings/)`wp-includes/class-wp-customize-manager.php` |

Prints JavaScript settings for parent window.

  | 
| [WP_Customize_Manager::is_ios()](https://developer.wordpress.org/reference/classes/wp_customize_manager/is_ios/)`wp-includes/class-wp-customize-manager.php` |

Determines whether the user agent is iOS.

  | 
| [media_upload_form()](https://developer.wordpress.org/reference/functions/media_upload_form/)`wp-admin/includes/media.php` |

Outputs the legacy media upload form.

  | 
| [_wp_customize_loader_settings()](https://developer.wordpress.org/reference/functions/_wp_customize_loader_settings/)`wp-includes/theme.php` |

Adds settings for the customize-loader script.

  | 
| [user_can_richedit()](https://developer.wordpress.org/reference/functions/user_can_richedit/)`wp-includes/general-template.php` |

Determines whether the user can access the visual editor.

  | 
| [_device_can_upload()](https://developer.wordpress.org/reference/functions/_device_can_upload/)`wp-includes/functions.php` |

Tests if the current device has the capability to upload files.

  | 
| [WP_Admin_Bar::_render()](https://developer.wordpress.org/reference/classes/wp_admin_bar/_render/)`wp-includes/class-wp-admin-bar.php` |  | 
| [wp_plupload_default_settings()](https://developer.wordpress.org/reference/functions/wp_plupload_default_settings/)`wp-includes/media.php` |

Prints default Plupload arguments.

  | 
| [_WP_Editors::editor_settings()](https://developer.wordpress.org/reference/classes/_wp_editors/editor_settings/)`wp-includes/class-wp-editor.php` |  |

[Show 4 more](https://developer.wordpress.org/reference/functions/wp_is_mobile/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_is_mobile/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_is_mobile/?output_format=md#changelog)󠁿

| Version | Description | 
| [6.4.0](https://developer.wordpress.org/reference/since/6.4.0/) | Added checking for the Sec-CH-UA-Mobile request header. | 
| [3.4.0](https://developer.wordpress.org/reference/since/3.4.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_is_mobile/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 4 content](https://developer.wordpress.org/reference/functions/wp_is_mobile/?output_format=md#comment-content-547)
 2.    [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/wp_is_mobile/#comment-547)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_is_mobile%2F%23comment-547)
     Vote results for this note: 12[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_is_mobile%2F%23comment-547)
 4.  **Example**
 5.      ```php
         <?php
         if ( wp_is_mobile() ) {
         	/* Display and echo mobile specific stuff here */
         }
         ?>
         ```
     
 6.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_is_mobile%2F%3Freplytocom%3D547%23feedback-editor-547)
 7.   [Skip to note 5 content](https://developer.wordpress.org/reference/functions/wp_is_mobile/?output_format=md#comment-content-3331)
 8.    [bantunes](https://profiles.wordpress.org/brunomiiguel/)  [  7 years ago  ](https://developer.wordpress.org/reference/functions/wp_is_mobile/#comment-3331)
 9.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_is_mobile%2F%23comment-3331)
     Vote results for this note: 7[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_is_mobile%2F%23comment-3331)
 10. Basic usage example:
 11.     ```php
         <?php if ( wp_is_mobile() ) : ?>
         	/* Display and echo mobile specific stuff here */
         <?php else : ?>
         	/* Display and echo desktop stuff here */
         <?php endif; ?>
         ```
     
 12.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_is_mobile%2F%3Freplytocom%3D3331%23feedback-editor-3331)
 13.  [Skip to note 6 content](https://developer.wordpress.org/reference/functions/wp_is_mobile/?output_format=md#comment-content-6358)
 14.   [Tom Rhodes](https://profiles.wordpress.org/tommusrhodus/)  [  3 years ago  ](https://developer.wordpress.org/reference/functions/wp_is_mobile/#comment-6358)
 15. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_is_mobile%2F%23comment-6358)
     Vote results for this note: 2[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_is_mobile%2F%23comment-6358)
 16. Note: Whilst caching issues are mentioned in [more information](https://developer.wordpress.org/reference/functions/wp_is_mobile/?output_format=md#more-information)
     for this function it cannot be re-stated enough that any page caching, which does
     not split itself into mobile and non-mobile buckets, will break this function.
     If your page caching is global and a desktop device triggers a refresh, the return
     of this function will always be FALSE until the next refresh. Likewise if a mobile
     device triggers the refresh, the return will always be TRUE. IF you expect the
     result of this function to change on a per user basis, ensure that you have considered
     how caching will affect your code.
 17.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_is_mobile%2F%3Freplytocom%3D6358%23feedback-editor-6358)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_is_mobile%2F)
before being able to contribute a note or feedback.