Discover in this tutorial how to completely delete the files in WordPress media library without going through the trash, using code.
By default, WordPress sends the files that we delete in the media library to the trash.
It’s nice that this is the usual behavior because it allows you to recover files you’ve accidentally deleted. But if you’re doing a media cleanup it can be a bit tedious to have to do an extra step.
The good thing is that you can change this behavior with one line of code.
Snippet to directly delete files from the WordPress media library
Add the following snippet to the end of the wp-config.php file (before the line /* That’s all, stop editing! Happy publishing. */):
From this moment on, when you go to delete a media instead of displaying “Send to trash” you will see “Delete permanently” and when you click on it, that’s what will happen. 😉
If you only want to change this behavior temporarily it is as easy as deleting the code once you are done with the “cleanup”.
You can see that with one line of code you can directly delete media from the WordPress library, without them going through the trash.
Any questions? Let me know in the comments.
And if you want to give me any suggestion for future tutorials, leave it in the contact form. Advantages of being a subscriber. 😉