Downloads an external image and optionally attaches it to a post.

Contains most of core’s media_sideload_image() but returns an attachment ID instead of HTML.

Note: this function does not validate the domain that the image is coming from. Please make sure to validate this before downloading the image. Should only pull down images from trusted sources.

Note: This function does not support GET params because these will not work on WPCOM production servers see r157060


Name Type Description
$image_url string URL of the image.
$post_ID int ID of the post it should be attached to.

Return Value

$thumbnail_id: id of the thumbnail attachment post id

Ready to get started?

Tell us about your needs

Let us lead the way. We’ll help you select a top tier development partner. We’ll train your developers, operations, infrastructure, and editorial teams. We’ll coarchitect your deployment processes. We will provide live support for peak events. We’ll help your people avoid dark alleys and blind corners, and reduce wasted cycles.