Default Media Saving in WordPress
WordPress by default saves all media files like images, videos and PDFs under the directory called “Uploads”. For example you can view an uploaded image in your site using the following path:
You have an option to arrange the media files in monthly folders under each year. You can enable the option “Organize my uploads into month- and year-based folders” available under “Settings > Media > Uploading File” section. With this option enable, you can view an image file uploaded on September 2014 in your site with the following URL:
Why You Need to Change Default Media Uploads Folder in WordPress?
It is easy to use the default setup as it is. However, you may have some problems or need to change the default media uploads folder in WordPress.
- 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. This will adversely affects the page loading speed. You can serve images from a subdomain or another domain to send parallel HTTP requests during the page load.
- Having lots of images in default uploads folder will affect your regular backup and restoring. You can keep the images in separate folder to manage them easily.
Change Default Media Uploads Folder in WordPress
For any reason, if you want to change the default media uploads folder in WordPress to a custom user defined folder, here is the step by step tutorial. 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
We will explain both the option in detail in the following section.
1. 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 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 your hosting account. Here we explain the File Manager option available with Bluehost cPanel. You can follow similar steps if you are using custom hosting panel like in case of SiteGround Site Tools.
Login to you hosting account, search for “File Manager” app and open it.
Choose the root direct where you have installed WordPress.
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. In this example, WordPress is installed in a sub-domain “wordpress.webnots.com”, so we create a new folder with the name “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 is correct 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 code in “wp-config.php” file and save your changes. The first line is a comment line for future reference, you can delete this line if not needed.
/** Change Media Upload Directory */ define('UPLOADS', ''.'media');
It should look like below in the file:
Ensure to add correct quotation marks 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. Also, make sure to add the code just above line “/*That’s all, stop editing! Happy blogging. */”
You can also use FTP software 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 “https://www.yoursitename.cm/media/media-file-name”. This will result 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.
Important Note: Though images uploaded through FTP or File Manager will show on the published site, you will not be able to see them under “Media > Library” section in admin panel. Unfortunately, WordPress will only show the files uploaded from the admin panel under media library. Follow the instructions in our article on fixing FTP images not showing in Media Library. In addition, you may need to check and change image hotlinking location if you are not able to see the images of published site in the browser.
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 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.
2. 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. As mentioned, by loading 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.