When you delete an article or page in WordPress, it goes into the system trash and is automatically deleted after 30 days. If you want to disable the WordPress auto delete trash feature, you need to add a little code to your WordPress site.
Prerequisites for Disabling the WordPress Auto Delete Trash Feature
- Basic WordPress file editing
- Using a Child Theme (Optional)
- Using a Plugin WPCode (Optional)
How to Disable the WordPress Auto Delete Trash Feature
To disable this auto delete trash feature, we can use two methods. One is by editing the functions.phpfile, and the other is by using the WPCodeplugin. If you want to use the functions.phpfile editing method, it is recommended to use a Child Theme.
1. Disabling the Auto Delete Trash Feature via functions.php
- Log in to your WordPress dashboard as an admin, typically via yourwebsite.com/wp-admin/
- Go to theAppearance > Theme File Editor
- menu. Find and editTheme Functions
- . Add the following code to the very last line ofTheme Functions , then save your changes.
function wpgan_no_autoremove_trash() { remove_action( 'wp_scheduled_delete', 'wp_scheduled_delete' );}add_action( 'init', 'wpgan_no_autoremove_trash' );2. Disabling the Auto Delete Trash Feature Using a Plugin
- Log in to your WordPress dashboard as an admin, typically via yourwebsite.com/wp-admin/
- Make sure you have installed and activated the WPCode – Insert Headers and Footers + Custom Code Snippets – WordPress Code Manager
- plugin. Go to theCode Snippets > + Add Snippet
- menu. Select theAdd Your Custom Code
- option. Add the following line of code in the available code box.
function wpgan_no_autoremove_trash() { remove_action( 'wp_scheduled_delete', 'wp_scheduled_delete' );}add_action( 'init', 'wpgan_no_autoremove_trash' );
COMMENTS
Loading...