admin管理员组文章数量:1434125
our site www.irish-pure.de has a slider. this header is currently deactivated for mobile via
@media (max-width: 640px) {
.theme-slider-wrapper {
display: none;
}
.benefit-bar__container {
margin-bottom: 1rem;
}
}
but when I check google pagespeed insights for the page, google recommends to avoid "hidden" images and lists the sliders images.
is there a way to remove the slider entirely for mobile in e.g., in the function.php or something?
thanks, E.
our site www.irish-pure.de has a slider. this header is currently deactivated for mobile via
@media (max-width: 640px) {
.theme-slider-wrapper {
display: none;
}
.benefit-bar__container {
margin-bottom: 1rem;
}
}
but when I check google pagespeed insights for the page, google recommends to avoid "hidden" images and lists the sliders images.
is there a way to remove the slider entirely for mobile in e.g., in the function.php or something?
thanks, E.
Share Improve this question edited Apr 7, 2019 at 12:27 fuxia♦ 107k39 gold badges255 silver badges459 bronze badges asked Apr 7, 2019 at 12:25 EleEle 1135 bronze badges 7 | Show 2 more comments2 Answers
Reset to default 1This is one of those problems that seems like it should have a simple solution, but really doesn't. There are options, they're just not easy.
At least, from what I can see.
CSS is the best approach to detecting browser width IMO. In fact, you really can't detect browser width from PHP. You can with JavaScript but that's where the complexities come in.
Even if you could detect browser width in PHP, you wouldn't want to. What if they made their browser bigger (i.e. rotated their device)? PHP is gone by that point, and can't add it back anymore.
There is a clever technique I read about where you use the new HTML5 image srcset to still serve an image at mobile resolution, but a very small one. However since you're using a slider, which I presume means a plug-in, you probably don't have that flexibility.
That leaves you with JavaScript. You could remove the images if the browser width is small, but you'd need to keep watching the viewport width in case it changed, and be ready to put them back. Probably better, only load them when needed (i.e. lazy load). It's possible your slider, or an alternative, would just natively give you that functionality.
You need to change the template that loads the slider. Assuming it is written in php you can use this class to detect if the site is loaded from mobile or not. If its loaded by mobile just don't render the slider.
http://mobiledetect
本文标签: slideshowremove slider mobile not via css
版权声明:本文标题:slideshow - remove slider mobile not via css 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745618428a2666540.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
wp_is_mobile()
function. With that said. You'll need to add a conditional around your slider code if you hope to do this. So if you can show your header.php or wherever the slider is in your theme, that would help get you a solution. – Howard E Commented Apr 7, 2019 at 15:43