Unexpected width and srcset attributes for the_post_thumbnail();

I am modifying a theme, using a child theme, and in a template file (single.php) I need to display a large post thumbnail, so I have this code:


In Settings > Media, the large size is set to max width = 1024px and max height = 1024px (I suppose these are the default settings in WordPress). Now, the problem is that in the post page I get this html code:

<img src=”https://example.com/wp-content/uploads/2018/07/example-image-4-1024×682.jpg”
class=”attachment-large size-large wp-post-image” alt=””
srcset=”https://www.example.com/wp-content/uploads/2018/07/example-image-4-1024×682.jpg 1024w,
https://www.example.com/wp-content/uploads/2018/07/example-image-4-300×200.jpg 300w,
https://www.example.com/wp-content/uploads/2018/07/example-image-4-768×512.jpg 768w,
https://www.example.com/wp-content/uploads/2018/07/example-image-4-272×182.jpg 272w,
https://www.example.com/wp-content/uploads/2018/07/example-image-4.jpg 1280w”
sizes=”(max-width: 800px) 100vw, 800px” width=”800″ height=”533″>

The result is that I get a 800px-wide picture, instead of a true “large” image that should be 1024px-wide. The problem seems to be in the “sizes” attribute that sets the max width to 800px, and the “width” attribute that sets the image to 800px. Those seem wrong to me. So what is happening exactly? If it’s caused by something in the theme, how do I find out where it is so that I can change it?

Looking at the documentation related to the_post_thumbnail(), I saw these filters:


So I tried looking for the string “post_thumbnail” and “attachment_image” in the theme, but that didn’t bring up anything useful. So what else do I look for? Note that I have some plugins installed (like Advanced Custom Fileds, etc.) but I tried deactivating them and the problem was still there, so I believe the source of the problem must be the theme, or something I don’t understand about WordPress.

Read more here:: Unexpected width and srcset attributes for the_post_thumbnail();

Leave a Reply

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