diary of an indie game developer

 

Disabling Comments in Old Wordpress Posts

I like leaving comments on for old entries, in case people happen across my site via Google and decide to say something. Some clients prefer to keep discussion on newer posts, though. Plus, given that most of the spam attempts happen to old entries, I can see the logic in shutting down comments on old posts.

There used to be a plugin floating around to do this, but it seems to be gone. I’m not going to make a plugin out of this change (though it would be helpful if you’ve enabled auto-update for Wordpress), but here’s how to disable comments on old posts:

  1. Open wp-includes\comment-template.php.
  2. Change this line:
    if ( 'open' == $post->comment_status)
    to this:
    if ( 'open' == $post->comment_status && time() < strtotime($post->post_date)+60*60*24*30 )
  3. Figure out what to do with the rest of your day.

The “60*60*24*30″ math up there is for 30 days (60 seconds times 60 minutes times 24 hours times 30 days), which you can of course change to whatever you’d like.

Like many Wordpress tweaks, the coding itself is trivial– you just need to know where to look. Speaking of which, ever want to know how to get a list of all the fields in the $post object? It’s in the documentation for the get_post function.

blog comments powered by Disqus