Skip Navigation

[Resolved] different image size inside view

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

Problem:

I want to display the full-size featured image on desktop and a smaller size (medium or thumbnail) on mobile devices. However, there is no built-in way to modify the [wpv-post-featured-image] shortcode to serve different image sizes based on screen size.

Solution:

Use two instances of the shortcode: one for desktop and one for mobile. Wrap each instance in a DIV with specific CSS classes, then apply CSS media queries to show or hide them based on screen width. The hidden image will not significantly affect performance due to modern browser optimization.

Relevant Documentation:

https://toolset.com/forums/topic/conditional-output-of-a-content-template-based-on-screen-width/#post-507471

0% of people find this useful.

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.

This topic contains 5 replies, has 2 voices.

Last updated by Christopher Amirian 2 months ago.

Assisted by: Christopher Amirian.

Author
Posts
#2750714

I have a view created in raypa.com that uses the following shortcode

[wpv-post-featured-image size="full"]

The full size is ok for desktop but too big for mobile. I would like to use the medium or thumbnail size for smaller screens. Is there a way to modify the shortcode - or some other way - to achieve that?

Thank you in advance!

#2751044

Christopher Amirian
Supporter

Languages: English (English )

Hi,

There is no way to use more than one image size inside the shortcode attributes.

But what you can do is to create to instances of the shortcode.

One for the desktop and the other one for the small devices.

Then wrap the desktop shortcode with an HTML DIV tag with a specific CSS CLASS that you can identify it is a desktop DIV tag.

Do the same for the small device shortcode to identify the smaller device DIV tag and use the typical CSS Media feature to show or hide one depending on the width of the device.

You can check the ticket below that explains something similar:

https://toolset.com/forums/topic/conditional-output-of-a-content-template-based-on-screen-width/#post-507471

Thanks.

#2751103

Hi Christopher,
thank you very much for taking the time to answer on a Sunday...!

I had thought already about the CSS route. My main concern about that is that if I hide an image with a display:none property, the image is still in the code, therefore it will still overload the page, or am I wrong?

If that is the case, this approach would not solve my problem I am afraid...

#2751350

Christopher Amirian
Supporter

Languages: English (English )

Hi,

Ok the image WILL be loaded. But these days the browsers are smart. So they will not load something that is set to display: none; first.

So it will not affect the performance and the page will load normally. but after the load of the other items are finished, the browser will load the hidden image in the background.

That should not have any effect on user experience.

I suggest that you do test the method and see for yourself.

Anyways, there is no way in Toolset to be able to differentiate between devices int he backend.

Thanks.

#2751633

Thank you for the explanation Christopher.

If there is no way to use more than one image size inside the shortcode attributes, I wonder whether there is a way to customize the custom field where the image comes from and set a condition there?

#2754390

Christopher Amirian
Supporter

Languages: English (English )

Hi,

There is a conditional feature available on the view and not the custom field section but it is not for the device-specific condition, it is more for logical conditions on the backend, for example, if a user is logged in or not, and these sorts of stuff.

Your need for detection of the front-end client to know if it is a desktop or mobile is a front-end related feature and you can not search for a backend solution for that.

I hope I could explain the situation clearly.

Thanks.