How does wordpress determine whether it is a mobile phone, tablet or PC and display the corresponding content-Mobile Detect

WBOY
Release: 2016-08-08 09:23:51
Original
1155 people have browsed it

How does wordpress determine whether it is accessed from a mobile phone, tablet or PC, and display specific content in a targeted manner? Mobile Detect, a lightweight PHP class library, can implement this function very well. Moreover, Mobile Detect also has a plug-in available under WordPress – WP Mobile Detect. WordPress uses this plug-in to easily implement the function of displaying specific content according to different terminal devices, such as responsive WordPress themes.

Install the WP Mobile Detect plug-in

Log in to the WordPress management background, select "Install plug-in" on the plug-in management page, then enter the keyword "WP Mobile Detect" in the search box, and then select "WP" on the search results page Mobile Detect" and install it.

Install the WP Mobile Detect plug-in

Search for the WP Mobile Detect plug-in

How to use WP Mobile Detect

Mark it with [keyword] in the wordpress article editor, such as

Mobile Detect How to use

or use functions in php code to determine

wpmd_is_notphone() – Returns true when on desktops or tablets
wpmd_is_nottab() – Returns true when on desktops or phones
wpmd_is_notdevice() – Returns true when on desktops only
wpmd_is_phone() – Returns true when on phones ONLY
wpmd_is_tablet() – Returns true when on Tablets ONLY
wpmd_is_device() – Returns true when on phones or tablets but NOT destkop
wpmd_is_ios() – Returns true when on an iOS device
wpmd_is_iphone() – Returns true when on iPhones
wpmd_is_ipad() – Returns true when on iPads
wpmd_is_android() – Returns true when on Android
wpmd_is_windows_mobile() – Returns true when on Windows Mobile

For example:

1

2

3

4

5

6

7

8

9

10

11

12

13

<?php if(wpmd_is_phone()){?>

<div>

Content visible only on mobile phones

</div>

&lt ;?php } elseif(wpmd_is_tablet()){ ?>

<div>

Content visible only on tablets

</div>

<?php } else{ ?>

<div>

Only PC viewable content

</div>

<?php } ?> ;

Original article, please indicate when reprinting: Reprinted from Wu Chuanbin’s blog http://www.mr-wu.cn/

Link address of this article: How does wordpress determine whether it is a mobile phone, tablet or PC and display the corresponding Content-Mobile Detect http://www.mr-wu.cn/mobile-detect-wordpress-plugin/

The above introduces how wordpress determines whether a mobile phone, tablet or PC is used and displays the corresponding content - Mobile Detect, including relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!