Posted in: WordPress Tutorials

How to Define Custom Media Uploads Folder in WordPress?

Do you want to define your own custom folder location for files and images uploaded by WordPress? You can easily change the folder location for uploads from /wp-content/uploads/ to any other folder within the root folder of your WordPress website installation. How to remove wp-content from the file uploads location URL in WordPress?

Here’s how to change the uploads media folder in WordPress.

Warning: If you are going to change the uploads folder location on an existing site, you will have to move your old uploads folder content to the new one. You will also have to change the uploaded file/images/media URLs in your WordPress database. You can use a find-replace plugin to search your WP database and make the necessary change.

Method 1: Define Custom Uploads Folder in WordPress Config

Go to your WordPress site root folder in your web server using File Manager. Locate and open wp-config.php file for editing. Now, add the following line just before /* That’s all, stop editing! Happy blogging. */.

If you want the upload directory to be outside wp-content, eg: https://wpflux.com/uploads/, you need to define the upload path in wp-config.php like this:

// Custom Folder for Uploads
define('UPLOADS','uploads');

If you want the upload directory to be within any folder, which can also be wp-content, eg: https://wpflux.com/resources/files/, you need to define the upload path in wp-config.php like this:

// Custom Folder for Uploads
define('UPLOADS','resources/files');

If you simply want to change the name of the uploads directory while leaving it within the wp-content foder, eg: https://wpflux.com/wp-content/files/, you need to define the upload path in wp-config.php like this:

// Custom Folder for Uploads
define('UPLOADS','wp-content/files');

The custom value is automatically taken relative to the ABSPATH, or the root folder of your WordPress installation. This means the uploads directory defined is located within the folder where your WordPress files are located. This is how WordPress defines the ABSPATH in its config file. This is just for your reference.

/** Absolute path to the WordPress directory. */
if ( !defined(‘ABSPATH’) )
define(‘ABSPATH’, dirname(__FILE__) . ‘/’);

Method 2: Advanced Custom Uploads Folder Settings in WordPress

Our previous method can only be used to define a new uploads folder within the root folder (ABSPATH) of our WordPress installation. What if you want the uploads folder to be outside the WP root folder?

To put it outside of ABSPATH tree, we cannot rely on the ‘define’ method. Prior to version 3.5, WordPress offered two options via ‘Settings -> Media’ screen: ‘Store uploads in this folder‘ (saved as upload_path) and ‘Full URL path to files‘ (saved as upload_url_path). These options are now hidden, but still present in WordPress as ‘upload_path’ and ‘upload_url_path’ in wp_options table as blank (default) fields. You can change the folder location value and the display URL for uploads folder by editing these two options in the WP options table using phpMyAdmin or accessing the options.php file in WordPress.

If you try to access the URL /wp-admin/options.php, it opens up a page which list all the options on your WP website installation. You can edit and modify these options from this page. In your browser, type the URL http://yourwpsite.com/wp-admin/options.php (of course, you replace your own website URL) to access the upload_path and upload_url_path settings. Change the settings with caution to the right values.