A Better Media Sideload Image

media_sideload_image is a WordPress function I have had to use countless times to upload attachments based on a provided URL. Often from Google Maps, but sometimes just from import scripts pointing to a URL. It has always worked well enough, but it has a couple of issues. The main problem is the lack of an ability to provide a filename separate from the image basename. This was especially ugly when generating static Google Maps…especially after Google Started requiring API keys…which WOULD BE SAVED AS PART THE FILE NAME!!!! Anyway, I looked around for a bit and found a really great solution on WordPress Stack Exchange from user Somatic.

It is a fairly large function so I’ll just provide the link:¬†https://wordpress.stackexchange.com/a/44115/57457

Trust me, if you want to use¬†media_sideload_image, use Somatic’s function instead.