20140802154525
I recently added a large image on the homepage.
Although the display on the computer is good, it's a waste on the mobile phone.
Because the width is certain, the display on the mobile phone and PAD completely damages the aesthetic
So I decided to hide the image on the mobile phone/PAD.
Hide a self-written function
Self-writing function hiding is a complicated method and is not recommended. However, if you are using a version earlier than WP 3.4, you can only use this method.
1. Edit function. php of the topic and add the following code (from WP EMY) to the end)
Function is_mobile (){
$ User_agent = $ _ SERVER ['http _ USER_AGENT '];
$ Mobile_browser = Array (
"Mqqbrowser", // mobile QQ Browser
"Opera mobi", // cell phone opera
"Juc", "iuc", // uc Browser
"Fennec", "ios", "applewebKit/420", "applewebkit/525", "applewebkit/532", "ipad", "iphone", "ipaq ", "ipod ",
"Iemobile", "windows ce", // windows phone
"240x320", "480x640", "acer", "android", "anywhereyougo.com", "asus", "audio", "blackberry", "blazer ", "coolpad", "dopod", "etouch", "hitachi", "htc", "huawei", "jbrowser", "lenovo", "lg ", "lg-", "lge-", "lge", "mobi", "moto", "nokia", "phone", "samsung", "sony ", "symbian", "tablet", "tianyu", "wap", "xda", "xde", "zte"
);
$ Is_mobile = false;
Foreach ($ mobile_browser as $ device ){
If (stristr ($ user_agent, $ device )){
$ Is_mobile = true;
Break;
}
}
Return $ is_mobile;
}
2. Find the content you want to hide. Use the following syntax to package it
<? Php if (! Is_mobile ():?>
// Write the code that is not displayed on the mobile phone.
<? Php endif;?>
3. If you want to display some code only on your mobile phone, use the following syntax:
<? Php if (is_mobile ():?>
// Only the code displayed on the mobile phone
<? Php endif;?>
4. Complete!
Hide using the wp_is_mobile () function
WordPress provides a function for us to determine whether a mobile phone is used, that is, wp_is_mobile (). We can use it to determine whether a mobile phone is used. However, this function only supports WP 3.4 or a later version, only the above method can be used for versions earlier than 3.4.
1. Find the content you want to hide. Use the following syntax to package it
<? Php if (! Wp_is_mobile ():?>
// Write the code that is not displayed on the mobile phone.
<? Php endif;?>
2. If you want to display some code only on your mobile phone, use the following syntax:
<? Php if (wp_is_mobile ():?>
// The code displayed on the mobile phone
<? Php endif;?>
3. Complete