I am doing an upgrade and cleanup of an old blog that started on Blogger.com, then moved to self-hosted WordPress 2.1, 2.3 and now 3.0. Images in the posts are scattered around: most of them are in /wp-content/, but not all in /wp-content/uploads/ or /wp-content/uploads/year/month/. Others still reference the blogger.com image servers. I want to consolidate them all in /wp-content/uploads/year/month/, which I think is the "correct" place? This should make later upgrades easier.

What is the best way to do this? I would like to update the metadata too, so that the Media Library can manage all of them. I could not find any documentation on this, so sorry if I missed it, please point me to it.

Of course, I would provide redirects from the old locations to the new. What is the best way to do this? A template 404.php, of a plugin? I would like to add some logging, so we can find the referring pages and maybe correct them.

(This question was originally asked on the WordPress support forums, but got no useful answer there).

  • are you looking for a plugin that does the job?
    – hakre
    Aug 19, 2010 at 11:07
  • Jan? Any feedback on your issue? Is no answer pleasing you? No comment helpful?
    – hakre
    Aug 27, 2010 at 22:25
  • I agree that some kind of media bulk-editor would be useful. Something that lets you import media from different folders and quickly move them around according to some rules. I might work on this actually.
    – noio
    Nov 10, 2010 at 21:00

4 Answers 4


W3-Total Cache has a feature that will scan all your posts and import any external images into the media library and change the paths to the new location.

See Screenshot

alt text


The correct place is the current setting I would say. So if you now use one upload folder (instead of years / month subfolders) go with that one (might get very full, but easier to sort. So just moving all files from the year / month subdirectories into the uploads directory and changing the URL-Paths in the database should normally do the job.

After all is in one folder (and sorted), you can change the folder design again, and move files into the correct directory with a PHP script that reads out the date from database. The exact same script needs to adopt URL paths again as well.

That's something like the exact same script that mike suggested.

Right now, the WP UI does not support to manually move or rename files, so you're bound to some own code. Which would make sense for a batch anyway.

Existing and Related Plugins

  • Add From Server (Wordpress Plugin) - "Add From Server" is a quick plugin which allows you to import media & files into the WordPress uploads manager from the Webservers filesystem

@Jan Fabry: You are probably going to need to tackle each case separately, i.e. the Blogger hosted images and the ones outside wp-content, etc.

Here's a plugin for importing from Blogger; it hasn't been updated in a while but may still work or at least have code you can use:

There's also an older plugin that may or may not still work:

Beyond that I think you'll just need to write a PHP script that scans your files and scans your posts looking for embedded image URLs, develops an intersected list and then moves the files and updates the reference in the post. Or maybe you'll get lucky and that plugin will still work and do it for you!

Good luck.


Maybe (and that's just for future readers - it's an old Q) you can list all 'post_type' => 'attachment' and start separating from there. I mean fetching the posts and saving the different locations in one array. Then sort this out to get an overview of where your images are lying around...

  • 1
    @kaiser: It may be an old question, but I'm still working on parts of it, so all suggestions are welcome! I hope to write down what I ended up with as an answer soon.
    – Jan Fabry
    Jan 13, 2011 at 8:48
  • @Jan: I guess i would call all 'post_type' => 'attachment' and then call the location (if this is stored somewhere in the query_vars) and if it doesn't exist in some predefined (first empty) array push it in there. With the result i'd try something with array_intersect or similar to just return the different locations. That's just some first and quick'n'dirty/rough thoughts about how to find out where the stuff is spread. So far i got no clue what i would do with the result or the redirect...
    – kaiser
    Jan 13, 2011 at 9:51
  • ...I guess it's possible to fetch the different attachments locations and then move them and update the location in the db. I wouldn't care to much about redirects. The post knows it, when the db knows it and who really cares about the indexing of post-attachments. You'd prefer that no one directly/hot links your images (or attachment-templates) and instead link to the containing post. I personally never used an attachment template or even set a link (aside from lightboxes and similar) to an attachment inside a post.
    – kaiser
    Jan 13, 2011 at 9:52
  • @kaiser: I currently first created redirects and moved all "lost" images under the /wp-content/uploads/moved/ directory. This way all posts, even those that reference old locations, will keep working, and my other directories are clear (which was the biggest problem for me: it was very unclear what belonged to WordPress and what didn't). Now I'm updating existing attachments and adding images that were not yet added as attachments.
    – Jan Fabry
    Jan 13, 2011 at 10:13
  • @Jan: "Now I'm updating existing attachments and adding images that were not yet added as attachments." Per hand - bit by bit? I don't know it exactly, but i guess you only need the redirects as long as the search engines don't know of the new location. The rest should rely on the db-entries. Wrong?
    – kaiser
    Jan 13, 2011 at 10:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.