Steps
-
Add the PHP code to your child theme’s
functions.phpfile or the Code Snippets plugin. -
Save and activate the snippet.
-
WordPress will use a seven-day trash retention period when its scheduled cleanup runs.
Hook Used
– empty_trash_days — Sets how many days WordPress retains trashed content before automatic cleanup.
Type: WordPress Maintenance
Output: Trashed content becomes eligible for automatic permanent deletion after seven days.
Customize: Change return 2; to another number, such as 7.
Warning: Permanently deleted content cannot normally be restored from WordPress Trash. Keep regular backups before enabling automatic cleanup.
function custom_set_trash_retention_period( $days ) {
return 2;
}
add_filter( 'empty_trash_days', 'custom_set_trash_retention_period' );
Tested on
Reported by the author on October 17, 2026. WPFolks has not verified this.
Not tested against WordPress 7.1.4. It may still work.
