Publish a featured image with the same name as the article title in wordpress

I have the following system, and I want the name of the featured image file to be generated differently each time. I want it to be based on the title prepared by ChatGPT. However, it should not have spaces, and once this is done, the featured image should be uploaded to WordPress.

Currently, every image that is uploaded is named file.png.

The desired format is: my-article-title.png

Can someone please guide me on how to do this?

I might start by using string functions to manipulate the ChatGPT article name. ChatGPT’s also pretty good at reformatting values, in my experience, but I like the certainty of an explicit transformation for simple stuff like this.

As a pretty trivial example, if the article name is like this:

image

…then you could use:

…to format it as an image title:

(I don’t know whether the file extension is included automatically in the Create a media item module. If so, just ignore the .png in my example.)

You could also use regular expressions inside replace() to deal with a wider range of undesired punctuation.

Finally, if you’re having issues making your image the featured image, then check out this post.

@Tully_Lanter , thank you for the advice and guidance. In which module should I insert the variable value? How should I structure the modules?

I need to solve this issue because if I don’t enter a different file name, all the featured images in WordPress overwrite with the same image.

I’m not positive, but based on this thread, you can do it through WordPress > Create a media item > File > Map.

You’d map the data from HTTP > Get a file and the file name from text functions.

Remember to create the media item before creating the post.