the_post_thumbnail ignores size parameter

I’m inserting an image in my theme as follows:

the_post_thumbnail('large');

Which results in the following HTML:

<img class="wp-post-image" width="660" height="440" sizes="(max-width: 660px) 100vw, 660px" srcset="https://wordpress.stackexchange.com/uploads/IMG-1024x683.jpg 1024w, https://wordpress.stackexchange.com/uploads/IMG-300x200.jpg 300w, https://wordpress.stackexchange.com/uploads/IMG-768x512.jpg 768w, https://wordpress.stackexchange.com/uploads/IMG-254x169.jpg 254w, https://wordpress.stackexchange.com/uploads/IMG-578x385.jpg 578w, https://wordpress.stackexchange.com/uploads/IMG-665x443.jpg 665w, https://wordpress.stackexchange.com/uploads/IMG-1600x1067.jpg 1600w" src="https://wordpress.stackexchange.com/uploads/IMG-1024x683.jpg">

Notice width="660" height="440" and sizes="(max-width: 660px) 100vw, 660px" which doesn’t correlate with the size defined for large in Media Settings > Image sizes which is supposed to be 1024 x 1024.

What am I doing wrong?

3 Answers
3

WordPress uses min( intval($content_width), $max_width ) inside image_constrain_size_for_editor for large image size.

As I can see your $content_width is set to 660. So, change the $content_width in your functions.php file to the 1024 or whatever you need. For full-width layout, it’s better to remove it.

Example: $GLOBALS['content_width'] = 1600. That’s it.

If you don’t know what content_width is, see Content Width for more info.

Leave a Comment