I’ve noticed recently that I’m getting a large amount of comment spam. This isn’t unusual, but what is strange is that most of it appears on the comments under images and attachments. Whilst this makes it easier to spot spam (because I know that anything left under an image is not going to be a useful comment), it’s quite annoying and I wondered if removing the ability to leave a comment under an image would reduce the amount of spam I get. WordPress is set up so that when you click on the thumbnail for an image, it will display the full image as a post, complete with a comment box underneath, like this:
Unfortunately, there is no general option to turn off comments under images or attachments. The solution I’ve found is to override the code in attachment.php which displays the comment box. Here is how I did this:
- My custom theme is based on the Thematic theme. The file used to generate the code to display attachments as a post is attachment.php. This file will also generate the code to display images as a post if image.php is missing (which in my case it is). So I copied attachment.php from /wp-content/themes/thematic to /wp-content/themes/mytheme
- I opened the copied file in Notepad++ and commented out the following line:
- I uploaded this file to the webserver and now the comments box no longer appears under attachments or images.
This solution isn’t perfect – as you can see if you click on the image above, underneath it still displays some text suggesting you leave a comment. But the comment box is no longer there which is the main thing. I’ll work on updating this text in future but hopefully I’ll now see a reduction in comment spam on image posts.