I upload external images for media library using following way.

$new_image_url = media_sideload_image($new_url, $post_ID, $title);

This method return complete img src tag or 'src' for the image URL.

I need to get image URL from it?

1 Answer 1


Try the fourth input parameter (available in 4.2+):

@param string $return  
       Optional. Accepts 'html' (image tag html) or 'src' (URL). Default 'html'.

So change your code snippet to:

$new_image_url = media_sideload_image($new_url, $post_ID, $title, $src = 'src' );

to get the src instead of the default html.

Note that the output might also be an WP_Error object for errors, so you might add a check for that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.