This month I’m designing a website for a client that’s already using WordPress. They’ve got years of posts, pages and images. I’d made an initial copy of their site a few months ago and now that the project is underway, I wanted to refresh my local copy of the uploads folder. It’s huge and I was trying to save time by just downloading what had changed.
Their media is stored in the ‘wp-content/uploads‘ folder. WordPress stores uploaded images within ‘wp-content/uploads‘ divided into year-month sub folders based on the configuration in Settings -> Media.
I thought I’d just delete my copy of the ‘uploads/2015‘ folder and then re-download it again. No need to download the previous years, right? WRONG. Turns out WordPress has a funny way of deciding where to put the newly uploaded files.
When you upload an image to an existing post or page with a published date in the past, it stores the image in the year-month folder that corresponds to the published date – not the upload date.
I decided to test it out for myself on a local development site. I’ve got a sample page that was published in September of 2014. I uploaded two images to the site. The first image (lavender) was uploaded via the Media Library without attaching it to the page. The second image (mower) was uploaded directly to the page.
The mower image was uploaded directly to the Sample page via the Add Media button while editing the page. The page was originally published in 2014.
As you can see below – the result is that each image was stored in a different location. That’s odd, ugh?
I discovered this quirky behavior after my local copy was missing images that were uploaded during the previous months – even though I downloaded the entire 2015 folder again. Turns out some of the images were stored in folders from 2010 and 2011. Why? The images were uploaded to a page that was published back then, even though they were uploaded in 2015. You’ll find this happening on pages and posts that are updated with new content after the original publish date. Like a What’s New page!
I did some digging online, and found a post from Gareth JM Saunders about uploading media to old posts that confirms this behavior.
[clickToTweet tweet=”#WordPress Heads up! Do you know where images are stored when uploaded to old pages and posts?” quote=”Heads up! Do you know where images are stored when uploaded to old pages and posts?”]
Whether is it a feature or a bug is debatable, especially on pages – as their published date is not as relevant as posts. What’s important is to understand how it DOES work, especially when migrating sites or selectively backing up your uploads folder.
One side note, if you are thinking why not just uncheck the settings box to store all the images in one folder, you’ve got two things to consider. First, some website hosts have limits on the number of files that can be stored in a single folder. Large sites with thousands of images in one folder may be a challenge to manage. The second is if you uncheck the box, it does not move the images that were previously uploaded. That would require moving them manually and updating their new location in the database.
So remember, where the image is stored is determined by how you upload it. The default is the current month’s upload folder, unless you add the image directly to a post or page with a published date in a different month.