开发者 | scottsweb |
---|---|
更新时间 | 2016年12月19日 18:12 |
捐献地址: | 去捐款 |
PHP版本: | 3.0 及以上 |
WordPress版本: | 4.7 |
版权: | GPLv2 or later |
版权网址: | 版权信息 |
mobble
folder to the /wp-content/plugins/
directory<?php is_mobile(); is_tablet(); // etc ?>
functions in your themes/templatesThe most useful ones are:
<?php is_handheld(); // any handheld device (phone, tablet, Nintendo) is_mobile(); // any type of mobile phone (iPhone, Android, etc) is_tablet(); // any tablet device is_ios(); // any Apple device (iPhone, iPad, iPod) ?>
You can also use:
<?php is_iphone(); is_ipad(); is_ipod(); is_android(); is_blackberry(); is_opera_mobile(); is_symbian(); is_kindle(); is_windows_mobile(); is_motorola(); is_samsung(); is_samsung_tablet(); is_sony_ericsson(); is_nintendo(); ?>
Inspecting Mobile_Detect.php
will also reveal some other useful tools.
Yup. This first example disables the sidebar for mobile/phone devices:
<?php if (!is_mobile()) { get_sidebar(); } ?>
This second example loads a specific stylesheet for Apple devices (iPhone, iPod and iPad):
<?php if (is_ios()) { wp_enqueue_style('ios', get_template_directory_uri() . '/ios.css'); } ?>
Please note that in certain setups caching will cause undesired behaviour. If your cache is set too aggressively PHP will be skipped and the device detection will not work.