Skip Navigation

[Resolved] Use of different images depending on viewport

This thread is resolved. Here is a description of the problem and solution.

Problem:

I want to use different images according to the viewport size, and show them alternatively. For instance one pic for mobile and another for large screens. Is this possible?

Solution:

I suggest you try the attribute "srcset" and "sizes" attributes of the img HTML tag, for example:

Views shortcode [wpv-post-featured-image size="large"] will be able to output the HTML image tags like this:

https://toolset.com/forums/topic/use-of-different-images-depending-on-viewport/#post-1170311

Relevant Documentation:

https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-featured-image

This support ticket is created 5 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 4 replies, has 2 voices.

Last updated by Luo Yang 5 years, 11 months ago.

Assisted by: Luo Yang.

Author
Posts
#1169919

Tell us what you are trying to do?
I'm using a template with Layouts. For large screens, I use images of 1400x280 px that show well. But when in small viewports, the responsive image shrinks and shows too small. I want to use different images according to the viewport size, and show them alternatively. For instance one pic for mobile and another for large screens. Is this possible? Is there any easier solution?

Relatedly, can I use in a template layout a picture that shows fullwidth in the screen? By default it shows the width of the column and I wonder if I can change the setting for this element.

#1170311

Hi,

I suggest you try the attribute "srcset" and "sizes" attributes of the img HTML tag, for example:
Views shortcode [wpv-post-featured-image size="large"] will be able to output the HTML image tags like this:

<img width="640" height="316" src="image-URL-1024x506.jpg" class="attachment-large size-large wp-post-image" alt="" srcset="image-URL-1024x506.jpg-1024x506.jpg 1024w, image-URL-1024x506.jpg-300x148.jpg 300w, image-URL-1024x506.jpg-768x379.jpg 768w, image-URL-1024x506.jpg-1568x775.jpg 1568w" sizes="(max-width: 640px) 100vw, 640px">

https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-featured-image

But if it is a custom image field created with Types plugin, you will need to setup the image HTML tags manually, more help:
hidden link

For example you can output the thumbnail size of image URL as below:
[types field="my-image" size="thumbnail" url="true"]

And use above codes in your image HTML tags to setup the "srcset" and "sizes" attributes
https://toolset.com/documentation/customizing-sites-using-php/functions/#image

#1171330
Make fullwidth an image in a template.jpg

Hello Luo. Thanks for your answer. I've solved the issue of changing the size of the images according to viewport size.

But I still need to solve the second question: Can I use in a template layout a picture that shows fullwidth in the screen? By default it shows the width of the column and I wonder if I can change the setting for this element.

Also, how can I eliminate the blank space between the image and the header menu?

#1172179

This is a custom CSS problem, I suggest you the solution of demo:
hidden link

If you need assistance for it, please provide a test site with the same problem, I can setup a demo for you.

#1173093

You are welcome