获取具有有效大小的当前页面的缩略图 URL



我有两种方法来检索我的插件

中实现的当前缩略图url
$post_thumbnail_id = get_post_thumbnail_id( $post_id );
$attachment = wp_get_attachment_image_src( $post_thumbnail_id );
echo($attachment[0])

输出:wp-content/uploads/2019/10/image-150x150.jpg

the_post_thumbnail_url()

输出:wp-content/uploads/2019/10/image.jpg

但是我正在寻找具有当前在文章/页面中使用的大小的特色图像的URL。

举例:wp-content/uploads/2019/10/image-1128x484.jpg

但是我希望能够检索URL的大小,无论当前正在使用显示在页面/帖子上的图像。

要获得特色图像URL,您可以使用get_the_post_thumbnail_url并提供您想要的特定大小作为参数。

$img_url = get_the_post_thumbnail_url($post_id,'full'); 

full替换为您要添加的大小。

最新更新