There’s nothing worse than receiving comment spamming on your WordPress site.
Well, there is actually and that’s receiving comment spamming on your media attachments! Grrrrr…..
Now there may be many WordPress users out there who are unaware of what this is, so let me tell you how it works and how annoying it is.
Spam, spam, spam, spam…
As you probably know, WordPress comes from a blogging background and it has allowed visitors to comment on posts since the Stone Age.
Anyone who has managed a WordPress site with a blogging area already knows the pains of moderating comments and removing the endless amount of spam that builds up there. (Hint: that’s what Akismet is for!)
You can of course turn comments off for new posts in the Admin Dashboard:
Settings >> Discussion >> uncheck “Allow people to post comments on new articles”
This applies to new posts that you will publish from now on. To disallow comments from already publish posts:
Posts >> select them all and “Edit” under bulk actions and hit apply >> choose “do not allow” next to comments and hit update posts.
There’s even a plugin that disables comments entirely. It’s called, yes you’ve guessed, Disable Comments. Gotta love those plugin developers 😛
What About the Social Factor
Disabling comments across your entire WordPress site is certainly one solution to stop spam, but what if you are trying to grow a social blog?
Surely not allowing visitors to comment and engage with your posts is a death sentence in today’s social media obsessed interwebbers.
Yes it is!
They only cost a few US dollars a month for all the features and they will trap a lot of your comment spam.
Oh – the Horror!
There is another type of spam that seems to be getting through those two systems – attachment comment spamming. Yes – finally we’re talking about this posts title – yay!
WordPress has a built in media gallery that includes images, videos, PDFs etc. and these are all added to posts as attachments.
You may not be aware but your visitors can leave a comment on any attachment in your media gallery.
Have a quick look at how many files you have in your media library just now. Go on.
Each one of these has the potential for a spammer to leave their dirty little mark on.
Oh – the horror….
Why Automattic (the developers of WordPress.com) thought that this was necessary I don’t know. I just think it’s pretty nuts, and of course, annoying when spammers start to flood your website.
Give Up, Roll-Over & Play Dead
That’s one way to handle the situation. The other is to fight back with geeky code and hit the spammers where it hurts – right in the bits.
Add the following code to your functions.php file:
Filters allow you to change the way WordPress does something. In this case, we are adding some code to the comments_open() WordPress function, telling it not to run if the post type is an attachment.
Of course backup your functions.php file before messing around with it, especially if you’re not a developer.
If mucking around in your code is too much bother, we’ve made the code into a plugin that you can download install and activate.