I would like to show product images from the description only on mobile devices. I don’t know how to split the images from the product.description.
<div class="product-description rte" itemprop="description">
// this works how I want it to. shows images and text
<div class="mobileShow">
{{ product.description }}
</div>
// if not mobile device only show text. strip out images.
{% if product.description contains "<img" %}
// ??
</div>
2
Answers
Why are you embedding product images in the description? You are making life very difficult for yourself. Why not just upload product images, and then make logic distinctions on how many, which ones, etc that you decide to use and where.
Manipulating product.images is far easier and dependable than embedding HTML hardcoded tags in your description.
If you’re wanting to hide all images within the description on mobile you can use a media query to target them.
The media query is dependent on the theme, though. Here’s an example:
You’d want to add that to the end of your scss file (most likely
theme.scss.liquid
.)The query above is for Simple and a few others – here’s the list:
@include media-query($small) {
@include at-query($max, $small) {