Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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).

share|improve this question

4 Answers

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

share|improve this answer

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
share|improve this answer

@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.

share|improve this answer

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...

share|improve this answer
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.
{"cc_re__cc_re__cc_by_sa_3_0": ["f=\"http://area51.stackexchange.com\" title=\"proposing new sites in the Stack Exchange network\">Area 51</a></li>\r\n                        <li><a href=\"http://careers.stackoverflow.com\">Stack Overflow Careers</a></li>\r\n                    \r\n                </ol>\r\n            </td>\r\n    </tr>\r\n</table>\r\n                </div>\r\n            </div>\r\n\r\n            <div id=\"copyright\">\r\n                site design / logo &copy; 2013 stack exchange inc; \r\n                user contributions licensed under <a href=\"http://creativecommons.org/licenses/by-sa/3.0/\" rel=\"license\">cc-wiki</a> \r\n                with <a href=\"http://blog.stackoverflow.com/2009/06/attribution-required/\" rel=\"license\">attribution required</a>\r\n            </div>\r\n            <div id=\"footer-flair\">\r\n                <a href=\"http://creativecommons.org/licenses/by-sa/3.0/\" class=\"cc-wiki-link\"></a>\r\n            </div>\r\n            <div id=\"svnrev\">\r\n                rev 2013.5.17.690\r\n            </div>\r\n                <div id=\"additional-notices\">\r\n                    WordPress is a trademark ", "\r\n</table>\r\n                </div>\r\n            </div>\r\n\r\n            <div id=\"copyright\">\r\n                site design / logo &copy; 2013 stack exchange inc; \r\n                user contributions licensed under <a href=\"http://creativecommons.org/licenses/by-sa/3.0/\" rel=\"license\">cc-wiki</a> \r\n                with <a href=\"http://blog.stackoverflow.com/2009/06/attribution-required/\" rel=\"license\">attribution required</a>\r\n            </div>\r\n            <div id=\"footer-flair\">\r\n                <a href=\"http://creativecommons.org/licenses/by-sa/3.0/\" class=\"cc-wiki-link\"></a>\r\n            </div>\r\n            <div id=\"svnrev\">\r\n                rev 2013.5.17.690\r\n            </div>\r\n                <div id=\"additional-notices\">\r\n                    WordPress is a trademark of the WordPress Foundation, registered in the US and other countries. This site is not affiliated with the WordPress Foundation in any way.\r\n                </div>\r\n            \r\n        </div>\r\n    </div>\r\n    <noscript>\r\n        <div id=\"noscript-warning\">WordPress Answers works best with Jav"], "copyright__copyright__copyright": [" 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...\n\nshare|improve this answer\nshow 2 more comments\n\nYour Answer\n\n\u00a0\ndiscard\n\nBy posting your answer, you agree to the privacy policy and terms of service.\n\nNot the answer you're looking for? Browse other questions tagged or ask your own question."]}