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:
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:
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".
Choose the root direct where your WordPress is installed.
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.
In the pop-up window enter the new folder name, check your root directory once and click on the “Create New Folder” button.
You can see the new folder with the name “media” is created under your WordPress installation.
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.
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).
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 */
You can also use FTP softwares like FileZilla to modify and upload "wp-config.php" file back to server.
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.
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...".
Ensure to select appropriate permission settings and the numeric value should be 755.
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.