G3N Services

How to change the upload folder in WordPress

Do you need to change the default path for uploading files in WordPress (default: wp-content/uploads)?

Previously, you could simply specify the desired address in the settings tab (Upload files -> Save files in this folder). Since version 3.5 this option has been removed.

The easiest way is to add the following lines to the wp-config.php file:

/** Folder for uploading files */
define('UPLOADS', 'wp-content/uploads/file');

Or even like this:

/** Folder for file uploads */
define('UPLOADS', 'files');

Then the path to the files will be: http://yourwebsite.com/files/

How to remove year and month from the address?

Go to «Options – Media» and uncheck «Organize my uploads into month- and year-based folders».

This is the easiest way to change the directory of uploaded files.

Another way to change upload folder

This method differs in that it allows you to change the folder only for the current upload. For example, we upload program files and screenshots to the site. Let the program files be stored in the /wp-content/uploads/file/ folder in the root of the site, and let the pictures be uploaded by default. Go to functions.php and add this code:

add_filter('upload_dir', 'wpshop_upload_dir');

function wpshop_upload_dir($upload) {
$time = current_time('mysql' );
$day = substr( $time, 8, 2 );
$upload['subdir'] .= "/file";
$upload['path'] .= "/file";
$upload['url'] .= "/file";
return $upload;
}

Possible problems

There is a high probability that with changing the upload path, all media files uploaded earlier will stop working.

If you have any questions or suggestions, feel free to message me on Telegram @g3nnadych or LinkedIn.