【问题标题】:Hiding WordPress sidebar if on phone only, not iPad, tablet, etc…如果仅在手机上隐藏 WordPress 侧边栏,而不是 iPad、平板电脑等……
【发布时间】:2013-12-29 00:03:27
【问题描述】:

我的网站侧边栏上有 Google AdSense,但在手机上看起来很糟糕。目标是在移动设备上查看侧边栏时将其删除,但将其保留在其他任何地方。因此,如果它在移动设备上,则隐藏它,但桌面和平板电脑会显示它。

如果发现了这个:

if (wp_is_mobile()) {
    // hide sidebar
} else {
    dynamic_sidebar( 'sidebar-1' ); 
}

这有效,但显然隐藏在包括平板电脑在内的所有移动设备上。是否还有其他功能可能仅适用于手机大小的屏幕?我曾尝试在 css 中使用媒体查询,但无济于事!

【问题讨论】:

  • I have tried to use media queries in the css but to no avail! 为什么?你尝试了什么?发生了什么?
  • 使用 css 媒体查询。如果没有 html 和 css 代码,我们将无法为您提供帮助。
  • 我将重复前面的评论以强调这是最好的解决方案。使用媒体查询。只需使用这个:Css Tricks Link
  • Detect if device is iOS的可能重复

标签: php jquery css wordpress responsive-design


【解决方案1】:

这成功了:

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();
}

【讨论】:

    【解决方案2】:

    使用 CSS 媒体查询。这是一个例子

    /* 智能手机(纵向和横向)----------- */

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

    .sidebar-1{display:none;}

    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-10
      • 1970-01-01
      • 2018-05-10
      • 1970-01-01
      • 1970-01-01
      • 2016-09-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多