I guess it’s no secret that the WordPress Media Library is one of the quirkiest and headache inducing components of the system. I’m in the process of cleaning up the Media Library on my main photography website, and while doing so, I’ve stumbled across two things that appeared to be annoying and/or weird. They’re interesting enough to share them, so here we go…
This is really super annoying, there’s no other way to put it. While doing some rename operations on my photos (thanks to Jordy Meow‘s Media File Renamer; I only use the manual renaming option of the Pro version though) I noticed that a lot of the associated thumbnail files didn’t appear to get renamed properly. What was going on there?
It’s not a bug in Media File Renamer. It’s a WordPress design problem – and a bad one! Each WordPress theme registers its own individual thumbnail sizes, and WordPress then automatically creates these thumbnails accordingly, when you upload an image. The problem arises when you switch the theme, or also when your theme is updated – ie. in any situation where the configured thumbnail sizes change. The old thumbnail sizes get unregistered from the WordPress configuration, all right – but the old thumbnails themselves remain online and don’t get cleaned up! There’s no built-in “garbage collection” for these stray files.
Now there are some plugins out there that try to fix this – one is a brute approach that simply deletes all thumbnails, so that you can then rebuild them. Sounds good, except that the plugin didn’t count past 1500 images when I tried it – and I have 3400 files online now…
Also, I was a bit hesitant to do batch operations on my entire Media Library with that many files now. Backups are all right, but why create a potential problem that will be a pain in the brain to fix? 🙂
So instead, I went through the upload folders one by one, manually, after doing my rename operations (that made it a lot easier to find the old and stray thumbnails because there’d only be thumbnail files without a basefile). It’s quite some work but it did allow me some insights that I found quite shocking: in a folder with about 50 photos, the leftover thumbnails take 5MB of disk space! That’s in ONE folder. I haven’t really watched my server disk-space, but by now I’ve probably deleted 100MB of useless old thumbnails. 100MB!
Upload directories by date
While going through the upload folders to clean out the thumbnails I noticed something else that was strange: newer files in older upload folders. Hu? Photos that I made and uploaded to the site in 2014 appear in a sub-folder of the year 2012?! How the heck did the photo upload to the site… back in time?!
I’m using the WordPress configuration where uploads go into monthly sub-folders in an annual parent folder in “wp-content/uploads/” – and I always thought that the current date determines where the files go.
But guess what, that’s not the case. 🙂 It turns out that what actually determines where the files go is the date of the parent post. If you have a post (a blog post, or a page, or custom post type) that is at least saved once as a draft, WordPress will put any attachments that you add to this post into the folder that corresponds to the date of the post – and not the current date!
I’ve been adding photos I made in 2014 to the gallery in a portfolio post (custom post type) that I first published in 2012 – and the 2014 photos ended up in the 2012 uploads directory structure! Very, very weird behavior if you ask me. But, I’m glad that I figured it out, since I’ve been shamelessly messing with the upload dates in order to get my photos sorted chronologically by actual capture date – and this frees the plugin that I’ve been using from any suspicions of messing up. 🙂
Now my problem is a different one of course, since I thought I could use the WordPress “uploads” directory structure to easily determine when I published a photo on my website… and I mean “published” in the sense that is important for copyright registrations with the US Copyright Office… I guess I need a different approach for that now. 😛
Anyway, I hope this little insight is helpful for someone out there. Let me know in the comments if you find some related quirks.
PS: None of this applies to wordpress.com hosted sites (like this one). Everything above is only for self-hosted WordPress.org sites. You can’t install plugins in wordpress.com hosted sites. You can’t access the “uploads” folder structure directly. You don’t see thumbnails. My guess is that they have “stuff” in place to handle this. At least I hope they do. 🙂