How to Disable the WordPress Auto Delete Trash Feature

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

  1. Log in to your WordPress dashboard as an admin, typically via yourwebsite.com/wp-admin/
  2. Go to theAppearance > Theme File Editor
    Cara Mematikan Fitur Auto Delete Trash WordPress
  3. menu. Find and editTheme Functions
    Cara Mematikan Fitur Auto Delete Trash WordPress
  4. . 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

  1. Log in to your WordPress dashboard as an admin, typically via yourwebsite.com/wp-admin/
  2. Make sure you have installed and activated the WPCode – Insert Headers and Footers + Custom Code Snippets – WordPress Code Manager
    Cara Mematikan Fitur Auto Delete Trash WordPress
  3. plugin. Go to theCode Snippets > + Add Snippet
    Cara Mematikan Fitur Auto Delete Trash WordPress
  4. menu. Select theAdd Your Custom Code
    Cara Mematikan Fitur Auto Delete Trash WordPress
  5. 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' );
  1. Change theCode Type to PHP
    Cara Mematikan Fitur Auto Delete Trash WordPress
  2. . Click theToggle Inactiveswitch so the status becomes active, then save.
    Cara Mematikan Fitur Auto Delete Trash WordPress
  3. Congratulations, the auto delete trash item feature on your WordPress site has been successfully disabled.

Written by

Muhammad Khoirun Nasikin

I enjoy tinkering with WordPress, hosting, VPS, web development, and various small experiments related to websites. I have over 3 years of experience in the web hosting industry.

COMMENTS

Loading...