Something you’ll be glad you did if you ever delete images by accident!
If you’ve ever accidentally deleted a vital image or document from your WordPress Media Library, only to realise there is no “Undo” button or site backup, you’ll know how it feels. By default, WordPress permanently deletes media files the second you click that red link.
However, you can add a safety net—a Trash folder for your media—with one simple line of code.
Why Enable the Media Trash?
In a standard WordPress installation, posts and pages have a “Trash” status, allowing you to recover them for up to 30 days. Curiously, the Media Library does not share this behavior out of the box.
By activating the Media Trash, you get:
- A Safety Buffer: No more accidental permanent deletions.
- Consistency: Your media workflow will match your post/page workflow.
- Peace of Mind: You can audit what is being deleted before it vanishes from the server forever.
Tutorial: How to Activate the Media Trash
To enable this feature, we need to edit your wp-config.php file. This is located in your root directory.
Step 1: Access Your Site Files
Log in to your website using an FTP client (like FileZilla) or the File Manager provided by your hosting control panel
Step 2: Locate wp-config.php
Find the file named wp-config.php in the public HTML folder of your site. Always create a backup copy of this file before editing it, just in case a typo occurs.
Step 3: Insert the line of code
Open the file in a text editor. Look for the line that says: /* That's all, stop editing! Happy publishing. */
Just above that line, paste the following code:
define( 'MEDIA_TRASH', true );
Note: Setting this to ‘
false‘ will disable the trash bin (the default state). To activate the bin, you must set the value totrue.
Step 4: Save and Test
Save the file (and re-upload it to your server if you edited it locally).
Now, go to your WordPress Dashboard:
- Navigate to Media > Library.
- Hover over an image. You should now see “Trash” instead of “Delete Permanently.”
- Once trashed, a new “Trash” filter will appear at the top of your media list, allowing you to restore the file or empty the bin.
Important Considerations
1. The 30-Day Rule
Once enabled, media items will stay in the trash for 30 days by default before WordPress automatically deletes them forever. If you want to change this duration (for example, to 14 days), you can add another line to your config file:
PHP
define( 'EMPTY_TRASH_DAYS', 14 );
2. Database & Storage Space
Remember that items in the Trash still take up space on your web server and entries in your database. If you are cleaning up a site to save disk space, remember to “Empty Trash” to actually free up that room.
3. “Delete Permanently”
Even with the Trash enabled, you can still skip the bin by clicking the “Delete Permanently” option within the Trash folder itself.
