Dealing with spam comments in WordPress is like swatting flies. What happens to those flies once you swat them? Akismet, the popular spam-fighting plugin, holds onto them in your database for 15 days by default in case you need to review them.
One of our readers asked if it is possible to tidy up their database more frequently by getting rid of that spam sooner. The answer is yes.
In this article, we’ll show you how to adjust Akismet’s spam deletion schedule to match your preferences, whether you want to purge that spam more often or keep it around a bit longer.
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.
Expert Guides on Combating Comment Spam in WordPress
We hope this article helped you change the Akismet spam comment deletion schedule in WordPress. You may also want to see some other articles related to combating comment spam:
- What is Akismet and Why You Should Start Using it Right Away
- Beginner’s Guide on How to Moderate Comments in WordPress
- Vital Tips and Tools to Combat Comment Spam in WordPress
- How to Easily Add reCAPTCHA to WordPress Comment Form
- How to Use Antispam Bee to Block Spam Comments in WordPress
- How to Quickly Batch Delete Spam Comments in WordPress
- How to Disable Trackbacks and Pings on Existing WordPress Posts
- How to Block IP Addresses in WordPress (& Why)
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.
Syed Balkhi
Hey WPBeginner readers,
Did you know you can win exciting prizes by commenting on WPBeginner?
Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
You can get more details about the contest from here.
Start sharing your thoughts below to stand a chance to win!
Dayo Olobayo
I completely agree with your approach to managing spam comments in WordPress. The ability to schedule deletions is a fantastic feature that can save a lot of time and effort. I find it particularly useful for dealing with large volumes of spam comments that can quickly accumulate.
WPBeginner Support
Glad you found it helpful
Admin