问题描述:

I have Google AdSense on my site’s my sidebar but it looks horrible on a mobile phone. The goal is to remove the sidebar if it’s viewed on a mobile device, but keep it everywhere else. So if it’s on a mobile device hide it, but desktop and tablets show it.

If have found this:

if (wp_is_mobile()) {

// hide sidebar

} else {

dynamic_sidebar( 'sidebar-1' );

}

Which works, but obviously hides it on all mobile devices including tablets. Is there another function perhaps that is just for phone size screens? I have tried to use media queries in the css but to no avail!

网友答案:

this done the trick:

function wp_on_phone() {
   if (!empty($_SERVER['HTTP_USER_AGENT'])

       // bail out, if iPad
       && false !== strpos($_SERVER['HTTP_USER_AGENT'], 'iPad')
   ) 
      return false;
   return wp_is_mobile();
}
网友答案:

Use CSS media queries. here is an example

/* Smartphones (portrait and landscape) ----------- */

@media only screen and (min-device-width : 320px) and (max-device-width : 480px) {

.sidebar-1{display:none;}

}

相关阅读:
Top