admin管理员组文章数量:1287918
I know that Wordpress has its way of letting the browser decide which image to download depending on the viewport via the srcset.
I also know that I can use the_post_thumbnail function and specify a custom size, like this:
the_post_thumbnail('my-custom-size');
Now, what I would like to achieve is being able to specify a list of custom sizes (of different aspect ratio from the original image), and letting the browser decide with one to use based on the viewport.
I DON'T want to just add a custom size to the list of possibilites in srcset, I want to choose the whole list of available sizes.
I DON'T want to override the general setting of srcset of the entire website. I want to specify this list of sizes only in one section.
Is this possible?
I know that Wordpress has its way of letting the browser decide which image to download depending on the viewport via the srcset.
I also know that I can use the_post_thumbnail function and specify a custom size, like this:
the_post_thumbnail('my-custom-size');
Now, what I would like to achieve is being able to specify a list of custom sizes (of different aspect ratio from the original image), and letting the browser decide with one to use based on the viewport.
I DON'T want to just add a custom size to the list of possibilites in srcset, I want to choose the whole list of available sizes.
I DON'T want to override the general setting of srcset of the entire website. I want to specify this list of sizes only in one section.
Is this possible?
Share Improve this question asked Feb 12, 2018 at 1:42 pietro morandinpietro morandin 32 bronze badges1 Answer
Reset to default 1The 2nd argument of the_post_thumbnail()
is an array of attributes and values, so you can just set your own srcset
attribute that way:
the_post_thumbnail(
'my-custom-size',
array(
'srcset' => wp_get_attachment_image_url( get_post_thumbnail_id(), 'my-other-custom-size' ) . ' 1000w',
)
);
本文标签: responsiveHow to select which thumbnails sizes are displayed in srcset
版权声明:本文标题:responsive - How to select which thumbnails sizes are displayed in srcset 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741331228a2372775.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论