Custom Upload Directory

By default, WordPress uses the same uploads folder for every uploaded media, no matter who uploads it, where they upload it from or the type of media it is.  This can cause problems for larger sites with lots of uploaded media, especially when many image sizes are created by WordPress.  It can not only be a headache to go through manually, it can actually slow down your site (if those folders have thousands of images each).

But, its really not too hard to better organize those uploads into folders that you control, based on the above criteria.  I use it to keep media associated with my portfolio page better organized.

This example has set a folder for each Custom Post Type.  With some simple tweaking, this can also be used for usernames, multisites, media type, post category or anything else you can think of.

Place the following in functions.php or create a plugin.

Dave focuses in WordPress UI Design and WordPress Plugin Development (some have labelled him a fanatic) but has hands in many other projects, including photography and music. He's never far from a computer... or an iPad (for testing purposes, of course). Don't even try to bother him during Premier League games, though... he's cheering way too loudly for a team destined to play second fiddle. Dave currently teaches courses in code and philosophy at California State University, Long Beach (well... from home for the foreseeable future) alongside his small business at dauid.us. But, every now and then, he steps outside to protest or give the dog a car ride.
© 2008-2024, dauid.us