I am currently trying to output post thumbnail URL with its different image sizes; to use in ssrcset.
My current code is:
<img class="productimage lazyload" data-src="<?php the_post_thumbnail_url('medium'); ?>" />
But, this always outputs the full size image instead of 'medium'. Also, I have tried to use first string 'null' or post ID; but this still does not work.
Is there any way I can output post thumbnail URL with specfic image sizes I want; for srcset?
Well, it is a custom theme so I don't know if I missed something. Please let me know if there is a way to make it happen.
I am currently trying to output post thumbnail URL with its different image sizes; to use in ssrcset.
My current code is:
<img class="productimage lazyload" data-src="<?php the_post_thumbnail_url('medium'); ?>" />
But, this always outputs the full size image instead of 'medium'. Also, I have tried to use first string 'null' or post ID; but this still does not work.
Is there any way I can output post thumbnail URL with specfic image sizes I want; for srcset?
Well, it is a custom theme so I don't know if I missed something. Please let me know if there is a way to make it happen.
Just use the the_post_thumbnail()
function. It creates the image tag, adds srcset
for you, and supports native lazy loading:
the_post_thumbnail( 'medium', [ 'class' => 'productimage' ] );