How to Change Default Media Upload Folder in WordPress?

Default Media Saving in WordPress

WordPress by default saves all media files like images, videos and PDFs under the directory called “Upload”. For example you can view an uploaded image in your site using the following path:

http://www.yoursitename.com/wp-content/uploads/media-file-name.png

In case if you have selected the check box “Organize my uploads into month- and year-based folders” available under “Settings > Media > Uploading File” then an image file uploaded on September 2014 in your site can be viewed with the URL:

http://www.yoursitename.com/wp-content/uploads/2014/09/media-file-name.png

Save Media File Under Month and Year
Save Media File Under Month and Year

Change Default Media Upload Folder in WordPress

For any reason if you want to change the default directory to a custom user defined folder, here is the step by step tutorial to change media upload folder in WordPress. You have two possibilities to change the upload folder:

  • Create a new folder within your WordPress installation
  • Create a new folder on a subdomain outside your WordPress installation

Creating Custom Folder Within WordPress Installation

This will help in added security by moving all your media files outside the /wp-content folder. Below are the basic steps involved in this process:

  • Creating a new folder for uploading
  • Modifying wp-config.php file
  • Moving existing media files to new folder
  • Check and correct broken media links
  • Upload media file and check permissions

Only first two steps are needed for a new WordPress site and all other steps are needed for an existing site already having media files.

Step 1 – Creating New Folder

Assuming you want to store all your media files under the directory called “media” then you need to first create a folder name in your root WordPress installation with a name “media”. You can create a folder either using FTP or using “File Manager” option accessible within cPanel of your hosting account. Here we explain the File Manager option available with Bluehost cPanel.

Login to you hosting account and open “File Manager” option available under “Hosting > cPanel > File Management > File Manager”.

Open File Manager in Bluehost
Open File Manager in Bluehost

Choose the root direct where your WordPress is installed.

File Manager Directory Selection in Bluehost
File Manager Directory Selection in Bluehost

Choose “Web Root (public_html/www)” if you installed WordPress in your root directory or select the sub-directory from “Document Root for” drop-down if you installed WordPress on sub-domain or sub-directory of a main domain. In this example WordPress is installed in a sub-domain “wordpress.webnots.com” so we create a new folder named “media” under the directory “wordpress”.

Click on the “New Folder” icon as shown in the below picture.

Create New Folder
Create New Folder

In the pop-up window enter the new folder name, check your root directory once and click on the “Create New Folder” button.

Enter Folder Name
Enter Folder Name

You can see the new folder with the name “media” is created under your WordPress installation.

New Media Folder Created
New Media Folder Created

Step 2 – Modify “wp-config.php” File

The next step is to modify “wp-config.php” file located under your WordPress installation root directory (normally “/public_html”). Click on the “Edit” icon in the “File Manager” as shown in the below picture.

Locate wp-config PHP File
Locate wp-config PHP File

If prompted, choose “utf-8” encoding in the pop-up and click on “Edit” button (You will not see this pop-up if encoding is disabled).

Choose Encoding for Text Editor
Choose Encoding for Text Editor

Add the following lines in “wp-config.php” file and save your changes. The first line is a comment line for future reference.

/** Change Media Upload Directory */
define('UPLOADS', ".'media');
Add Code for Changing Media Folder
Add Code for Changing Media Folder

Ensure to add correct single and double quotes in the code, copying the code from text editor like Microsoft Word will add different type of quotes in WordPress and makes the code not effective.

Add the code just above line “/*That’s all, stop editing! Happy blogging. */”

You can also use FTP softwares like FileZilla to modify and upload “wp-config.php” file back to server.

Edit wp-config Using FileZilla
Edit wp-config Using FileZilla

Step 3 – Moving Existing Files to New Media Folder

Once you changed “wp-config.php” file, all existing media attachments in your WordPress site will be automatically changed with the URL “http://www.yoursitename.cm/media/media-files” resulting in broken media links in all your posts and pages. You need to move all existing files to new “media” folder to adjust the broken links. You can do this either by FTP or inside your “File Manager” by just dragging and dropping all the media files from old directory to new directory.

Move Existing Files to New Media Folder
Move Existing Files to New Media Folder

Step 4 – Check For Broken Link

The final step is to check for any missed broken links of media files in your site. You can use plugins or external websites like brokenlinkcheck to find any broken links and correct them manually.

Any new media file uploaded in your site will be stored under the new “media” folder.

Step 5 – Upload Media File and Check Permissions

Finally upload an image and check the file path that it is stored in new “media” folder created. If you see image not found or 403 error then the probable reason could be file permission settings of newly created folder. In order to check the file permissions, connect your FTP software to the server and navigate to the folder. Right click and select the option “File Permissions…”.

Change File Permission Settings in FileZilla
Change File Permission Settings in FileZilla

Ensure to select appropriate permission settings and the numeric value should be 755.

Setting File Permissions in FileZilla
Setting File Permissions in FileZilla

Creating Custom Folder on Subdomain Outside WordPress Installation

Storing media files on external domain provides lot of flexibilities like independent backup, faster site loading in addition to added security. Whenever the webpage is loaded, browser will trigger separate HTTP request to server for every single image on the page putting lot of load on the server which adversely affects the page loading speed. By loading the images from external subdomain all images can be loaded in parallel thus increasing the page loading speed.

Refer the step by step tutorial on hosting images on subdomain in WordPress.

Try out one of these options and leave your comments if you face any problem.

Editorial Staff at WebNots are team members who love to build websites and share the learning with webmasters community. Follow us on Facebook and Twitter.

24 thoughts on “How to Change Default Media Upload Folder in WordPress?”

Leave your response.

  1. Hello,
    Thank you for this instruction. I added the code to the wp-config.php file and it works in that if I add a new image to the media library, it goes into the new ‘images’ file. The problem is that all of the images in the media library already, now show as broken in the library.

    All of the old images are in the new ‘images’ file, in fact they were already in there because this system was already set up before I moved the site to a new server and the config file changed. When I changed it back with this code, it is having the above problem.

    define(‘UPLOADS’, ‘images’);

    Reply
  2. The change to wp-config.php will actually break your site. The instructions are wrong — the missing double quote will cause a server error. Just google for different instructions and you’ll find some that don’t break your site.

    Reply
    • We use preformated text for codes to retain the quotes, however make sure you check when pasting on your configuration file.

      On side note – no matter from which website you are copying, make sure to take care of single and double quotes.

      Reply
  3. This is the fix recommended by all WP advice sites. Unfortunately, changing wp-config not only changes the default for uploaded media, but also changes the default used by some themes and page builders (e.g. Elementor).

    Once I saw this, I restored the original setting – organizing media by upload month is just brain-dead, but it’s the only way to isolate uploaded media from the other content created by themes and plugins…

    IMO, making this change is a bit risky.

    Reply
    • That’s the intended purpose of changing the media folder similar to storing all static files in Uploads folder. Otherwise, you will get lost if some files are in media folder and some are in uploads folder.

      That’s also the reason plugin developers refer the upload file path from configuration settings. If you want your plugin to follow the uploads folder then change the settings only within the plugin leave the global settings as it is.

      Reply
  4. Is it possible to change un-select “Organize my uploads into month- and year-based folders” on a LIVE site? Are the current images and pdf files path changing too?

    Reply
  5. Good Day,

    When I type in your code in my cPanel using Edit, it breaks my site with a white screen and no error. When I remove the code, my site works again. I did use the 4 single quotes and 1 double, plus copy/dragged all images to new folder. Permission is correct on the folder I wish to use instead of /uploads. My new folder had a dash, so I tried removing that without success

    I am working on a Duplicator plugin copy of my sites to change things up without touching the live ones. Good thing or my live site would go down. Though I’m not sure why working on a copy would be any different … Could this be the reason?

    In other words, instead of working on nameofsite.com, I’m working on test.nameofsite.com On this particular site, I’m using a WP version back a few, albeit don’t think that would matter.

    Thanks in advance and Merry Christmas to you & yours!

    Reply
    • Please disregard. I figured out that I needed to add your code to a different place within the config file. Namely beneath the require_once(ABSPATH…. bit. Now it works perfectly! Thanks!

      Reply
      • Glad to know you find it yourself, you shall add the code just above the line “/* That’s all, stop editing! Happy blogging. */”

        Reply
        • But if I do that, then it breaks my site. As I stated above, I had to put it at the end of my config file after

          require_once(ABSPATH ….

          Not before the “/* That’s all, stop editing! Happy Blogging! */”

          Perhaps it’s a plugin or my theme that causes me to place it differently? Anyway it works so no worries :) Thanks again!

          Reply
  6. Hello,

    My site no longer loads and I get the following error after trying to set this up?

    Parse error: syntax error, unexpected $end, expecting T_VARIABLE or T_DOLLAR_OPEN_CURLY_BRACES or T_CURLY_OPEN in /home/websitename/public_html/wp-config.php on line 84

    Could you advise me on what I did wrong? Your instructions were very succinct so I’m surprised by the outcome I’m getting?

    Thanks in advance

    Reply
    • Check the quotes you used in the code. As already highlighted in the article, if you copy from text editor the single / double quotes will be in different format which will not be parsed and show error.

      Reply
      • First of all thank you for getting back to me! I actually figured out the problem steming from the double quote vs two single quotes. That being said in the WP Dashboard, whenever I select <> WP still attempts to look for the folder in it’s previous location? I haven’t been able to figure out why it will not look in it’s new location (running WP 4.0). I really wanted my media files outside for wp-content folder…If you have any recommendations I would appreciate it!

        Reply
        • Are you referring the URL (…/wp-admin/upload.php) in browser’s address bar when you click on “Media” inside WordPress admin dashboard? If yes, it is a “Media Library administration panel” file stored under your “wp-admin” folder as “upload.php” which will not affect where your files should be stored.

          To check file path, upload a new file and check the “File URL” which should show the new folder. Or if you have any existing images on your site, right click and copy image URL, which should show that the image is stored under the new “media” folder you created.

          Reply
          • Thanks for this info, i as a beginner was also looking that URL. Now that i checked and everything is working fine.

Leave a Comment