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?
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.Sign up to join this community
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
Note that the output might also be an
WP_Error object for errors, so you might add a check for that.