·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> 网站建设开发 >> php网站开发 >> wordpress如何判断手机、平板还是PC并显示对应的内容-Mobile Detect

wordpress如何判断手机、平板还是PC并显示对应的内容-Mobile Detect

作者:佚名      php网站开发编辑:admin      更新时间:2022-07-23
WordPRess如何判断手机、平板还是PC并显示对应的内容-Mobile Detect

wordpress如何判断是手机、平板还是PC访问,并针对性的显示特定的内容?Mobile Detect 这个轻量级php 类库能够很好的实现这个功能。而且Mobile Detect也有wordpress下的插件可用–WP Mobile Detect,wordpress使用这个插件,很容易实现根据不同终端设备显示特定内容的功能,比如响应式wordpress主题。

wordpress如何判断手机、平板还是PC并显示对应的内容-Mobile Detect - 第1张  | 吴川斌的博客

安装WP Mobile Detect插件

登录wordpress管理后台,在插件管理页面选择“安装插件”,然后再搜索框里输入关键字“WP Mobile Detect”,然后再搜索结果页面李选择“WP Mobile Detect”并安装即可。

wordpress如何判断手机、平板还是PC并显示对应的内容-Mobile Detect - 第2张  | 吴川斌的博客

安装WP Mobile Detect插件

wordpress如何判断手机、平板还是PC并显示对应的内容-Mobile Detect - 第3张  | 吴川斌的博客

搜索WP Mobile Detect插件

WP Mobile Detect如何使用

在wordpress的文章编辑器里用[关键字]进行标注,例如

wordpress如何判断手机、平板还是PC并显示对应的内容-Mobile Detect - 第4张  | 吴川斌的博客

Mobile Detect 如何使用

或者在php代码里用函数进行判断

wpmd_is_notphone() – Returns true when on desktops or tabletswpmd_is_nottab() – Returns true when on desktops or phoneswpmd_is_notdevice() – Returns true when on desktops onlywpmd_is_phone() – Returns true when on phones ONLYwpmd_is_tablet() – Returns true when on Tablets ONLYwpmd_is_device() – Returns true when on phones or tablets but NOT destkopwpmd_is_ios() – Returns true when on an iOS devicewpmd_is_iphone() – Returns true when on iPhoneswpmd_is_ipad() – Returns true when on iPadswpmd_is_android() – Returns true when on Androidwpmd_is_windows_mobile() – Returns true when on Windows Mobile

例如:

12345678910111213<?php if(wpmd_is_phone()){ ?><div>仅手机可见内容</div><?php } else if(wpmd_is_tablet()){ ?><div>仅平板电脑可见内容</div><?php } else { ?><div>仅PC可见内容</div><?php } ?>

原创文章,转载请注明:转载自吴川斌的博客http://www.mr-wu.cn/

本文链接地址:wordpress如何判断手机、平板还是PC并显示对应的内容-Mobile Detecthttp://www.mr-wu.cn/mobile-detect-wordpress-plugin/