Q. Have you ever wondered why your images are broken after cloning your WordPress site’s database and copied the latest folders from wp-content/uploads?
A. There’s a simple answer. You didn’t copy all of the latest images.
Problem solving – verse 24
And regarding the data, you'll think that I'm a chump "but does it work on Windows running last Wednesday's dump"?
It’s very easy to get broken images in WordPress.
- Export your production database
- Import your production database into a local development environment
- Update wp_options to make it work
- Forget about copying the attached media files
To resolve this issue you copy the attached media files from the latest months’, so that your directory structures match.
Sorted? Not quite.
You may have missed some images that were uploaded recently but are not where you might have thought they should have been.
- Here we see a broken image in my local copy of oik-plugins.com
- This new image was uploaded in October 2014
- But the post that it was attached to (the oik themes server plugin) was originally created in July 2013
- So WordPress put the newly attached media file in the 2013/07 folder
- And since my previous database clone was more recent than July 2013 I didn’t clone the uploads folder
Techniques for future consideration
It won’t just be media files that are out of date; there’s plugins and themes and even WordPress core that may be different. So it makes sense to take a full backup of the files as well.
Alternatively, when adding a new media file to an existing post, use this process:
- Use Media > Add New to upload the file
- Attach the file to the post
- Edit the post to make the changes required to refer to the new file
- And if necessary, delete the file(s) that the new file replaces.
Suppose you have some content that is valid from a certain date. It would look odd if it appears to have been stored in the system earlier than it was created. And maybe you should also consider displaying the Last update date for your main content.
This is a good idea for date sensitive files such as a Statement of Professional Standing, Newsletters attached to a Newsletters page, or banner images for new versions of plugins 🙂