Easy Guide to Change Akismet’s Delete Spam Schedule in WordPress

In this tutorial, we will learn how to change Akismet’s delete spam schedule in WordPress.

Why Change How Akismet Deletes Spam in WordPress?

This tutorial is for Akismet plugin only. If you are not using it, then check our guide on why you should start using Akismet.

Akismet allows you to combat comment spam in WordPress. It monitors all comments, pingbacks and trackbacks.

Spam comments reside in your database, which means they increase your database backup size. Deleting them sooner may help keep your database size a bit smaller.

While some users may believe that deleting spam comments improves database performance, we don’t think it has a major effect on database performance in most circumstances.

If you are receiving thousands of spam comments, and you try to delete them manually, then it could affect your site’s performance. See our guide on how to batch delete spam comments in WordPress.

On the other hand, some users may want to keep spam comments for a longer period, so that they can review them later to avoid false positives.

Having said that, let’s see how you can change the delete schedule for spam comment in WordPress with Akismet.

Changing Spam Comment Delete Schedule in WordPress with Akismet

Akismet automatically deletes spam comments after keeping them for 15 days in your database. This gives you time to manually review spam comments.

If it marked a genuine comment as spam, then you can mark it as not spam. This is how Akismet learns and improves it’s algorithms to catch spam comments more efficiently.

Changing Spam Comment Delete Schedule in WordPress

You can change the number of days Akismet should keep spam comments in your database. Simply add this code to your theme’s functions.php file or in a site-specific plugin.

add_filter( 'akismet_delete_comment_interval', 'custom_spam_delete_interval' );
 
function custom_spam_delete_interval() {
    return 7;
}

Change 7 with the number of days you want to keep a comment. This filtersimply modifies Akismet’s spam deletion schedule.

Changing the number to 0, will allow Akismet to delete all comments on its next comment delete schedule. This will not give you much time to review spam comments.

You can see your changes in action by visiting Settings » Akismet page. Scroll down to the bottom of the page, and you will see a note in tiny letters saying ‘Spam in the spam folder older than 7 days is deleted automatically.’

 Settings » Akismet Scroll down to the bottom of the page.

It will replace 7 days with the number of days you used in your filter.

Note: When spam comments are deleted, they are not sent to trash, so you cannot retrieve them back.

We hope this tutorial helped you change Akismet spam comment delete schedule in WordPress.

Leave a Reply