After we published our article on how to change the WordPress trash schedule, one of our readers asked if it was possible to change the deletion schedule for spam comments.
Akismet is a comment spam plugin that comes with WordPress but is not activated by default. Akismet will normally keep spam comments in your WordPress database for 15 days before deleting them.
In this article, we will show you how to change Akismet’s delete spam schedule in WordPress.
Why Change How Akismet Deletes Spam in WordPress?
This tutorial is for the 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 live 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 deletion schedule for spam comments 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.
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 use a code snippet plugin such as WPCode (recommended):
add_filter( 'akismet_delete_comment_interval', 'custom_spam_delete_interval' );
function custom_spam_delete_interval() {
return 7;
}
For more details, just see our guide on how to add custom code in WordPress without breaking your website.
Change 7 with the number of days you want to keep a comment. This filter simply 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.’
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 the trash, so you cannot get them back.
We hope this article helped you change the Akismet spam comment deletion schedule in WordPress. You may also want to see our guide on how to get a free SSL certificate or our expert pick of the best Twitter plugins for WordPress.
If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.
Have a question or suggestion? Please leave a comment to start the discussion.