customization - Wordpress 5: including larger thumbnail image sizes in srcset than I have set

I have set image sizes in my functions.php, such as add_image_size( 'article-lede', 500, 600 );It shows up in

I have set image sizes in my functions.php, such as

add_image_size( 'article-lede', 500, 600 );

It shows up in Regenerate Thumbnails, and I regenerated them. So I upload an image to the media library which is 934x1200.

My template code is set to use the "article-lede"image:

<?php the_post_thumbnail('artcle-lede', ['class' => 'featured-image img-fluid']);?>

But the page shows a full-size image. And the img tag in the resulting HTML has the height and width set to the large size, and an SRCSET of sizes, none being the article-lede size I specified:

<img src="http://mysite/wp-content/uploads/2019/11/keiltys.jpg" class="featured-image img-fluid wp-post-image" alt="" srcset="http://mysite/wp-content/uploads/2019/11/keiltys.jpg 934w, http://mysite/wp-content/uploads/2019/11/keiltys-234x300.jpg 234w, http://mysite/wp-content/uploads/2019/11/keiltys-797x1024.jpg 797w, http://mysite/wp-content/uploads/2019/11/keiltys-768x987.jpg 768w, http://mysite/wp-content/uploads/2019/11/keiltys-467x600.jpg 467w, http://mysite/wp-content/uploads/2019/11/keiltys-311x400.jpg 311w" sizes="(max-width: 934px) 100vw, 934px">

How I do get it to display the 500x600 version?

I have set image sizes in my functions.php, such as

add_image_size( 'article-lede', 500, 600 );

It shows up in Regenerate Thumbnails, and I regenerated them. So I upload an image to the media library which is 934x1200.

My template code is set to use the "article-lede"image:

<?php the_post_thumbnail('artcle-lede', ['class' => 'featured-image img-fluid']);?>

But the page shows a full-size image. And the img tag in the resulting HTML has the height and width set to the large size, and an SRCSET of sizes, none being the article-lede size I specified:

<img src="http://mysite/wp-content/uploads/2019/11/keiltys.jpg" class="featured-image img-fluid wp-post-image" alt="" srcset="http://mysite/wp-content/uploads/2019/11/keiltys.jpg 934w, http://mysite/wp-content/uploads/2019/11/keiltys-234x300.jpg 234w, http://mysite/wp-content/uploads/2019/11/keiltys-797x1024.jpg 797w, http://mysite/wp-content/uploads/2019/11/keiltys-768x987.jpg 768w, http://mysite/wp-content/uploads/2019/11/keiltys-467x600.jpg 467w, http://mysite/wp-content/uploads/2019/11/keiltys-311x400.jpg 311w" sizes="(max-width: 934px) 100vw, 934px">

How I do get it to display the 500x600 version?

Share Improve this question asked Nov 25, 2019 at 16:37 SteveSteve 3139 silver badges21 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Good question as I know that this can be a pain in the butthole. Please see this page; https://developer.wordpress/reference/functions/get_the_post_thumbnail_url/.

From the docs:

get_the_post_thumbnail_url($id, 'image-size')

So in your case:

$img = get_the_post_thumbnail_url($post, 'article-lede');
echo "<img src='{$img}' class='featured-image img-fluid' />";

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744966588a4603718.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信