How to Change the WordPress Media Upload Directory

By  on  

One thing I've always missed about the "old" way of web development was the simplicity of FTP. No deploy scripts, no fuss: simple drag and drop of files and the files are there. I've used FTP for assets on this blog for over a decade but I'm finally ready to be lazy enough to want to drag images into WordPress and use them as WordPress intended.

The problem is that I want the files to upload to custom directory, not the wp-content/uploads directory that WordPress defaults to. The following PHP snippet in the WordPress wp-config.php file allows you to change WordPress' default upload directory:

require_once(ABSPATH.'wp-settings.php');
define('UPLOADS', 'my-demo');

Files uploaded within the WordPress / browser interface will be added in this custom directory. Note that WordPress will create the directory if not present, and will also automatically create and upload the file to a {year}/{month} directory within that custom directory.

I wish I had set this configuration years ago. Having to open a separate app and then write the custom HTML to insert this image has been an inconvenience for a long time!

Recent Features

  • By
    Responsive and Infinitely Scalable JS Animations

    Back in late 2012 it was not easy to find open source projects using requestAnimationFrame() - this is the hook that allows Javascript code to synchronize with a web browser's native paint loop. Animations using this method can run at 60 fps and deliver fantastic...

  • By
    Send Text Messages with PHP

    Kids these days, I tell ya.  All they care about is the technology.  The video games.  The bottled water.  Oh, and the texting, always the texting.  Back in my day, all we had was...OK, I had all of these things too.  But I still don't get...

Incredible Demos

  • By
    Using MooTools to Instruct Google Analytics to Track Outbound Links

    Google Analytics provides a wealth of information about who's coming to your website. One of the most important statistics the service provides is the referrer statistic -- you've gotta know who's sending people to your website, right? What about where you send others though?

  • By
    MooTools Link Fading

    We all know that we can set a different link color (among other properties) on the hover event, but why not show a little bit more dynamism by making the original color fade to the next? Using MooTools 1.2, you can achieve that effect. The MooTools...

Discussion

  1. shawn caza

    If you don’t want to mess with the config file, you might be able to use wordpress’s secret hidden settings page to do this: https://your-site.com/wp-admin/options.php

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!