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(); ?>
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:
<?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
The download price of this resource istwoelementBuy Now(VIP free)upgrade now
Professionally provide WordPress theme installation, in-depth localization, accelerated optimization and other website construction services. Please consult online customer service for details!