Set a featured image from a URL

MediaIntermediate~10 minUpdated

Before you start

A connected site with the upload-media-from-url and set-featured-image write abilities enabled. The URL must be HTTPS and point straight at a public image file (a link that redirects is refused), and the image must be a jpg, png, gif, or webp; SVG is rejected. The upload tool needs a filename, so the agent proposes one in the first step.

You found the right image for a post, and it is sitting at some URL. The manual version is download, rename, upload through the media library, then open the post and set the featured image. Four steps and a browser tab shuffle for one picture.

Here the agent does the fetching and the busywork, and you keep the one decision that matters: yes, use this image on this post. It is a write, so it waits for that yes before anything lands.

The prompt
Set the featured image on [post ID 142] from this image URL:
[https://example.com/photo.jpg]. The link has to be HTTPS and the image a
jpg, png, gif, or webp. Before you upload, show me the source URL, the
file name you will use, and the post it will go on, and wait for my
go-ahead. Once I approve, fetch it into the media library with the
upload-from-URL tool and set it as that post's featured image, then tell
me the new attachment ID.

Why this is safe to run

There are two writes here and both are narrow. The upload adds one new image to the media library, and setting the featured image points one post at that attachment. Neither touches the post body, its status, or anything already in your library.

The fetch rules do real work. The plugin only fetches HTTPS links to public hosts, refuses private and internal addresses, does not follow redirects, and decides what the file is by reading its bytes rather than trusting the link. An SVG or an unrecognized format is rejected outright, so nothing questionable gets stored. On top of that, the write abilities stay off until you enable them, every call is checked against the capability of the user you bound the agent to, and the upload and the featured-image change both land in the Activity Log. If you set the wrong image, you point the post at a different one, and the post copy is never affected. There is no tool that clears a featured image back to none, so remove one in the editor.

Already connected? You do not have to paste this. Ask your agent for the “set a featured image from a URL” recipe, or just point it at an image and a post, and it runs the same upload and approval flow on your own site.

How it works

  1. Give the agent the image URL and the post you want it on.
  2. It shows you the source, the file name, and the target post, and waits.
  3. On your go-ahead, the plugin fetches the image from the URL into the media library.
  4. It sets that new attachment as the post's featured image.

Questions

Who fetches the image, the agent or the plugin?
The plugin. Upload media from URL takes an HTTPS link and fetches the file itself. It refuses private, loopback and link-local addresses and does not follow redirects, so the link must point straight at the image file. It decides the file type from the bytes it receives rather than from the link.
What if I pass an SVG, an odd format, or an http link?
The upload is rejected. Only jpg, png, gif, and webp are accepted, and the link has to be HTTPS, so anything else stops at the door and nothing is written.