WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/wp is mobile

Description

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. Works through the detection of the browser user agent string ($_SERVER['HTTP_USER_AGENT'])

Usage

<?php wp_is_mobile(); ?>

Parameters

This tag does not accept any parameters.

Examples

<?php
if ( wp_is_mobile() ) {
	/* Display and echo mobile specific stuff here */
}
?>

You should realize that this does not detect a mobile phone specifically, as a tablet is considered a mobile device. Check the Plugins area for several helpful alternatives.


Change Log

  • 4.0 -- Works by testing HTTP_USER_AGENT for any of the following : [ Mobile, Android, Silk/, Kindle, BlackBerry, Opera Mini, OperaMobi ]. Does not consider resolution, window width, or any other factors.
  • Since: 3.4

Source File

wp_is_mobile() is located in wp-includes/vars.php.

See also index of Function Reference and index of Template Tags.