WordPress Tutorial

WordPress judges the mobile device function to load the code

 Alibaba Cloud

At present, the mainstream of WordPress supports the mobile end style, but the support of some blog topics for the mobile end is not very satisfactory. There are also some styles that we don't want to display on the mobile end, such as the right sidebar of some websites. Although you can't see them when you visit the mobile end, they are just hidden, not loaded on demand. This article will teach you how to use WordPress to judge mobile device functions for on-demand loading!
WordPress Mobile functions have been supported since WordPress 3.4.

 <? php wp_is_mobile(); ?>

 weeiy.com_2015-03-10_14-08-49
For example, the analysis bar is displayed incorrectly on the mobile terminal. Of course, in order to be lazy, I directly set it to not display on the mobile terminal through the function. The recommended code is as follows:

Want to be here? contact us bar
 Maker host
 <? php if ( wp_is_mobile() ){ ?> (This is set as the content to be displayed on the mobile terminal, and the WeChat rice does not need to be displayed, so it should be blank) <? php }else { ?> For non mobile device display, the content of your computer is set here, and the content will not be displayed for mobile access <? php } ?>

After the above code optimization, Wefan's mobile display will not load the right sidebar, which improves the loading speed of the website.
There are also the following solutions: mobile terminal and computer terminal output the specified content:

 <? php if ( wp_is_mobile() ){ Echo 'You are browsing with mobile device'; }else{ Echo 'You are not using a mobile device'; } ?>

If you don't understand, please leave a message.
If your website needs optimization, please contact Maker Cloud for paid optimization services.

WordPress judges the mobile device function to load the code

615 people have bought
View Demo Upgrade VIP Buy Now

Collection
fabulous ( zero )

Post reply

Hot selling template

Ashade - Works exhibition photo album WordPress Chinese theme
 LensNews

This site accepts WordPress/PbootCMS/DedeCMS, etc
System construction, imitation, development, customization and other services!