How to pass a YouTube thumbnail URL through the a custom image size

I’m currently displaying YouTube thumbnails directly from YouTube using this format which works:

<img src=”http://img.youtube.com/vi/<?php echo youtube_id; ?>/maxresdefault.jpg” />

Instead I want to be able to pass this URL through some custom image sizes I’ve created in my theme so I can generate smaller version to be used for the srcset attribute.

add_image_size( ‘youtube_thumbnail_370x208’, 370, 208 );
add_image_size( ‘youtube_thumbnail_480x270’, 480, 270 );

From what I can see custom image sizes only seem to work on images that are uploaded via WordPress and not with external image paths. Is this correct or is there a better way to do this?

I know YouTube can provide smaller image sizes but they are either too small, poor quality or don’t fit the 16:9 ratio I need.

Read more here:: How to pass a YouTube thumbnail URL through the a custom image size

Leave a Reply

Your email address will not be published. Required fields are marked *