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;
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745346604a4623578.html
评论列表(0条)