Images that you upload to your WordPress website are stored in the wp-content/uploads folder by default. When you first install WordPress you have the choice whether to separate the images by months and years. It is an important decision to make at that time because it can affect how you want your image files organized. In some future time, for example, if you wanted to resize those images to reduce your website size or to optimize them to increase the loading speed of your webpages — and they are stored by year and month in different folders — you would have a difficult time opening and closing those folders to make the changes without the help of some sophisticated software.
You can change that decision, of course, any time. If you go to General Settings > Media in the WordPress dashboard and scroll down the page to the Uploading Files section, you can tick or untick the checkbox for Organize my uploads into month- and year-based folders depending on what you want. But it would only affect the organization of new images. Images already uploaded to your website would remain organized based on your previous decision.
The decision to change the default uploads folder in your WordPress-powered website is an important decision to make. It comes hand in hand with that checkbox in the General Settings > Media page in the WordPress dashboard. If somehow you find yourself wanting to change how your images are organized for esthetic reasons or needing to move the default uploads folder to another location for security reasons, this tutorial is for you. Please finish reading this article first before you move your images to a new location in your website as this results in broken image links. So, you really have to be sure you want to change the default uploads folder before doing it.
1. Decide on how to organize the images
Go to General Settings > Media in the WordPress dashboard. Scroll down the page to the Uploading Files section and tick or untick the checkbox for Organize my uploads into month- and year-based folders depending on what you want.
2. Change the location of the uploads folder
Decide where to put your custom uploads folder. Do you want to put it in the same level as the wp-admin, wp-content and wp-includes folders? Do you want it inside the wp-content but outside the uploads folder?
Open the wp-config.php file and look for the ABSPATH lines of code, as shown below:
/** Absolute path to the WordPress directory. */ if ( !defined('ABSPATH') ) define('ABSPATH', dirname(__FILE__) . '/');
If you want your new uploads folder (let’s say the folder name is media) to be in the same directory level as the wp-admin, wp-content and wp-includes folders, insert the following code before the ABSPATH lines of code:
/** Change Media Upload Directory */ define( 'UPLOADS', 'media' );
Have a look at this image:
If you want the media folder to be inside the wp-content folder but outside the uploads folder, use the following code instead:
/** Change Media Upload Directory */ define( 'UPLOADS', 'wp-content/media' );
3. Move the images into the “media” folder
After doing the first two steps, move your website images to your specified folder or folder location in Step 2. This results in broken image links, so you will need to download two tables afterwards from the database and replace the links to fix them. Image links in articles can be found in the wp_posts table in the database. Thumbnail links are in the wp_postmeta table. Reminder: Always keep a backup of your database or database tables before making any changes to avoid any data loss!
4. Protect the “media” folder
Create a .htaccess file inside the media folder and write the following code in it to disable directory browsing and prevent hackers from accessing any file in it:
# Disable directory browsing Options All -Indexes