media_sideload_image


media_sideload_image ( $file, $post_id, $desc = null, $return = 'html' )

Parameters:
  • (string) $file The URL of the image to download.
  • (int) $post_id The post ID the media is to be associated with.
  • (string) $desc Optional. Description of the image.
  • (string) $return Optional. Accepts 'html' (image tag html) or 'src' (URL), or 'id' (attachment ID). Default 'html'.
Returns:
  • (string|WP_Error) Populated HTML img tag on success, WP_Error object otherwise.
Defined at:
Change Log:
  • 4: .
  • 4: .

Description

Downloads an image from the specified URL and attaches it to a post.

Related Functions

media_upload_image, media_upload_file, media_handle_sideload, media_upload_video, wp_load_image

Top Google Results

User discussions

wpseek mobile