admin管理员组文章数量:1420907
I have already read and that's not the answer to my question.
The above answer will download the image from the source and upload the library. I just want to set external URL(image URL) as the featured image without downloading my own server.
I have already read https://stackoverflow/questions/41524931/how-to-set-featured-image-programmatically-from-url and that's not the answer to my question.
The above answer will download the image from the source and upload the library. I just want to set external URL(image URL) as the featured image without downloading my own server.
Share Improve this question asked Jul 4, 2019 at 9:43 I am the Most Stupid PersonI am the Most Stupid Person 5681 gold badge7 silver badges30 bronze badges1 Answer
Reset to default 1You can use the post_thumbnail_html
filter to set the post thumbnail programmatically to an external URL.
Then you wold set the image URL in a Custom Field on the post writing screen metabox (in this example with a meta key of thumbnail_url
):
add_filter('post_thumbnail_html', 'custom_thumbnail_tag_filter', 10, 3);
function custom_thumbnail_tag_filter($html, $postid, $thumbnailid) {
if (!$thumbnailid) {
$src = get_post_meta($postid, 'thumbnail_url', true);
if ($src) {$html = "<img src='" . $src . "'>";}
}
return $html;
}
本文标签: post thumbnailsHow to set featured image from external url programmatically
版权声明:本文标题:post thumbnails - How to set featured image from external url programmatically 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745346604a2654513.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论