wp_is_mobile() - WordPress 函数参考中文文档

返回介绍

wp_is_mobile()

发布于 2017-09-11 字数 2634 浏览 985 评论 0

wp_is_mobile()

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


描述


返回值

(bool)


源代码

File: wp-includes/vars.php

function wp_is_mobile() {
	if ( empty($_SERVER['HTTP_USER_AGENT']) ) {
		$is_mobile = false;
	} elseif ( strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false // many mobile devices (all iPhone, iPad, etc.)
		|| 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;
}

更新日志

Version 描述
3.4.0 Introduced.

相关函数

Used By

  • wp-includes/class-wp-customize-manager.php:
    WP_Customize_Manager::customize_pane_settings()
  • wp-includes/class-wp-customize-manager.php:
    WP_Customize_Manager::is_ios()
  • wp-admin/includes/misc.php:
    _ipad_meta()
  • wp-admin/includes/media.php:
    media_upload_form()
  • wp-includes/theme.php:
    _wp_customize_loader_settings()
  • wp-includes/general-template.php:
    user_can_richedit()
  • wp-includes/functions.php:
    _device_can_upload()
  • wp-includes/class-wp-admin-bar.php:
    WP_Admin_Bar::_render()
  • wp-includes/media.php:
    wp_plupload_default_settings()
  • wp-includes/class-wp-editor.php:
    _WP_Editors::editor_settings()
  • Show 5 more used by
    Hide more used by


User Contributed Notes

  1. Skip to note content

    You must log in to vote on the helpfulness of this noteVote results for this note: 1You must log in to vote on the helpfulness of this note

    Contributed by Codex

    Example

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!