Change the_post_thumbnail() based on screen size
-
Hi All,
I’m looking to swap between two different images based on the user’s screen width. My dilemma is this:
The design for desktops serves up a slideshow image that is 1170px X 420px, but when the browser sizes down to a mobile device ( < 768px ) the image is much too short. I’d like to swap it with another custom thumbnail size I created so it’s less image size to load for mobile devices.
These are my custom image sizes in my functions.php
add_image_size( 'featured', 770, 433, true ); add_image_size( 'carousel', 1170, 420, true);
and my PHP (using Advanced Custom Fields plugin for custom content):
<? $attachment_id = get_field('slide_image'); $image = wp_get_attachment_image_src( $attachment_id, $size ); ?> <img src="'<? $image[0]; ?>'" alt=" ">
I need the $size variable to change based on screen size.
Any suggestions?
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Change the_post_thumbnail() based on screen size’ is closed to new replies.