Assign Any Section to Show on Mobile or Desktop Only

Assign Any Section to Show on Mobile or Desktop Only

Compatability:  All Shopify themes

I have multiple people who wants to assign a different image to their desktop user customers and mobile user customers. The step is very easy actually and just follow along.

Since some themes are written differently, you might need to hire a developer to do this for you. In some sections, this can be a little tricky since we need to add the class code to the section or the first container. 

To start:

1. Go to Admin > Online store > Themes > Actions > Edit code
2. Open the section you want to edit. Then find the first "<" (angle bracket) that you see, and look for the class section. 
3. Add the code below. NOTE: Make sure to provide a space. 

{{ section.settings.show_on_device }}

 

If you do not have a "class" in your first "<", you can add one by using the format below. Paste the bold letters below.

<div class="{{ section.settings.show_on_device }}" .....

4. Next, we will need to add a schema, so you do not have to the coding everytime. Go down to the {% schema %} section. Find the "settings", under the section. Add the code below after the "[", please make sure to watch the video for proper placement.

{
"type": "select",
"id": "show_on_device",
"options": [
{
"value": "mobile--device",
"label": "Mobile and tablet device"
},
{
"value": "desktop--device",
"label": "Desktop device"
},
{
"value": "show-all-devices",
"label": "Show to all devices"
}
],
"default": "show-all-devices",
"label": "Show this section to this device only",
"info": "Choose which device you want this section to show"
},

5. Next, we need to add the CSS file to hide and show on whatever choice of device you have. Go to Asset folder, and open the base.css or theme.css or theme.scss for others. Then add the code below. Make sure to SAVE

@media only screen and (max-width: 749px) {
.desktop--device {
display: none !important;
}
}
@media only screen and (min-width: 750px) {
.mobile--device {
display: none !important;
}
}

 

 

39 comments

Hi there, I tried this again and I’m still having both desktop and mobile show on the desktop version. The mobile version works perfectly, it’s just the desktop.
Can you please assist with this?
Thank you

Sharyn

Hi,
These are the issues that users do wrong:
1. Placement of the Step#3. They place the said code in the id instead of the class or even place it just wherever.
2. Forgot to follow the steps. They are missing step #4 and step #5.
3. Try to customize the code. Some user tries to customize the CSS code and done it wrong.
4. The main base.css or theme.css has errors. I have seen users that just added random codes from other sources and that creates error on their main CSS file.

Made4Uo

Hi!
Great tutorial, clear and concise and exactly what I was after, only problem is it isn’t working for me.
All the instructions have been followed and I get the ‘Show this section to this device only’ choice in the theme editor, but the slideshows still show on all devices regardless of which option I choose.
My test slideshows are on this page https://www.atvsonly.co.uk/pages/test labelled as ‘desktop’ and ‘mobile’, if you could have a look and hopefully show me what I’ve done wrong that would be great!
Thanks,
Iain

Iain

Hi @JESSICA,

Make sure you follow the instructions as explained in the video. The code must be placed in the first “<”. For some sections, this will cause an error since they make a section as a container, if this is the issue, we need to provide the code differently. Please contact us using “Chat with us”

@JAMIE Thank you so much for the appreciation!

@SHAIMA This is a little off topic but I would recommend to replace your image with bigger sizes

Made4Uo

Hello! I added this code to the Image Banner. When I choose hide from desktop, it removes the image from desktop, but leaves a huge white space where the section is. This also happens if I choose hide from mobile. Is there any way to resolve this?

Jessica

Just wanted to drop a line and say thank you. Easy to understand an implement, appreciate your work.

Jamie

Hi! thank you so much for this simple tutorial :))
I have noticed that mobile banner quality is quite low although i have adjusted its dimensions from canva. is there a way to fix this?

my site for reference -

https://marthajewelry.myshopify.com/
test

shaima

Hi @LEON,
I am not sure what are you trying to obtain. Are you trying to hide the whole product in a product page? Anyway, you can add a class to the line. E.g. class=“the code here”

Made4Uo

Hello,
I want to apply this to my “Product information” but in my code “main-product.liquid” there is no “Class” or “<”.
What can I do?

Leon

Hi @YAREMIS,

As mentioned in the video, you place the {{ section.settings.show_on_device }} at the first angle bracket, “<”. For slideshow, the first angle bracket is “<slideshow-component”, you have to place the code inside the class. Some of the angle brackets might not have a “class=’’”, just add the code inside the angle bracket, “class=’{{ section.settings.show_on_device }} ’”. Some circumstances, you might need a developer to do so.

Made4Uo
« Previous 1 2 3 4 Next »

Leave a comment