Add media from a URL
wp_upload_media_from_urlDownload a file from a public URL and add it to the WordPress media library as a new attachment, with optional title, alt text and post attachment.
Instructions
Download a file from a public http(s) URL and add it to the media library; the file is public under its new URL afterwards, and each call adds a new file. The site fetches the file itself through WordPress' safe-URL check, repeated on every redirect: private and internal hosts are refused unless WordPress allows them (such as the site's own host); at most 3 redirects, 20 seconds per request, 20 MB by default (filter ab_mcp_upload_max_bytes). The URL or the content type must name JPEG, PNG, GIF, WebP or PDF; HTML, SVG, XML and script responses are refused, and WordPress then checks the file as for any upload. No third-party API is involved. Returns {uploaded: true, id, url}. Needs upload_files, and the right to edit post_id when given. File content at hand is uploaded as base64 with wp_upload_media.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| alt | No | Alternative text for an image, stored as plain text. | |
| url | Yes | Public http(s) URL of the file. Your site downloads it; nothing is sent anywhere else. | |
| title | No | Title of the new attachment. | |
| post_id | No | Id of a post to attach the file to; needs the right to edit that post. Default: attached to no post. |