I’m using media_sideload_image to download images from the web and store them. However, the problem is that the ones from youtube are always called “hqdefault.jpg”, which means that it will override the existing image. There are three ways of fixing this:
- How can I change the attachment structure so that it includes the postname? (Current: http://example.com/wp-content/uploads/2011/10/hqdefault-40×40.jpg)
- How can I set the filename of the attachment to the postname, thus preventing overrides.
- How can I set a new filename of an existing attachment thumbnail?
Many thanks,
Dennis
When I started using
media_sideload_image()
, I found it pretty useless as it returned a full html tag, instead of the attachment ID, so I created my own version of it which replicates all the functionality ofmedia_sideload_image()
and adds some very useful stuff, like:post_thumbnail (featured image)
Just call the function below instead of
media_sideload_image()