I’ve always got quite a lot of comment spam on the blog, and this is mostly for older posts that I assume are already dead and wouldn’t be commented on. If you go back far enough, you find all sorts of rubbish on this blog since its been running since before I did web development as a proper living.

In order to stem some of this (its still nice to double check what Askimet thinks is spam actually is) – I thought it would be a good idea to disable the ability to add new comments to older posts.

I think at the moment, anything over a month can probably have this function disabled, so I added the following bit of code in my single.php theme file.

< ?php
$timeofpost = get_the_time('Y-m-d');
$timenowMinus30 = date('Y-m-d',strtotime(date('Y-m-d') . '-30 days'));
if($timeofpost > $timeNowMinus30){
	comments_template( '', true );
}?>

Which seems to be working quite nicely at the moment!

Image Credit: Werner Kunz