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 badges
Add a comment  | 

1 Answer 1

Reset to default 1

You 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