Wordpress Snippets

Automatically Empty Trash in WordPress

When you delete a post, page, or comment from your blog, it will be moved to the Trash folder. This feature makes it extremely difficult to accidentally delete a post or page from your WordPress website. Items within your trash folders can be restored or permanently deleted within 30 days after it is sent to the trash which is the default time limit in WordPress. Each item after 30 days of their original trashing will be permanently deleted and it’s not possible to restore them.

If you are one of those people who is always very careful about what they delete or what they don’t, then you can disable trash completely and can choose to permanently purge items as you hit delete button. Although I am strongly against this idea or disabling WordPress trash feature because you never know when you need to restore a item you accidentally hit delete button. I would suggest that you keep this feature enabled but configure it to be automatically cleaned every day, if cleaning trash every week is not an option.

To automatically empty trash in WordPress every week, you can paste this little code snippet in wp-config.php file. It will permanently delete each item 7 days after it is sent to the trash.

// automatically empty trash weekly
define( 'EMPTY_TRASH_DAYS', 7 );

Else, if you want to automatically empty trash daily then you can change constant’s value to 1, like this.

// automatically empty trash daily
define( 'EMPTY_TRASH_DAYS', 1 );

Now if you are absolutely sure that you want to disable trash then you can set this value to 0. This will make the trash functionality will be disabled and the ‘Delete Permanently’ button will appear instead of ‘Trash’ button. If you click ‘Delete Permanently’ button, the item will immediately deleted without any alert message.

// disable wordpress trash completely
define( 'EMPTY_TRASH_DAYS', 0 );

Hire Us. Or just say Hi!
Need a job? Apply to get one.