functions - <?php the_post_thumbnail_url('medium'); ?> not outputting medium size image URL

admin2025-01-07  4

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.

Share Improve this question asked Mar 26, 2021 at 7:16 Rishabh KundraRishabh Kundra 11 bronze badge 1
  • Is your original image smaller than the 'medium' image? If so then WP will return the 'full' image. – Andy Macaulay-Brook Commented Mar 26, 2021 at 11:04
Add a comment  | 

1 Answer 1

Reset to default 0

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' ] );
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736257474a441.html

最新回复(0)