Block Contact Form 7 Spam Emails by Keywords (Quick & Free Method)

Tired of “guest post’, backlink, casino, and SEO spam flooding your inbox?

Here’s a simple and effective way to silently block unwanted Contact Form 7 submissions based on specific words or phrases.

No plugin required

Lightweight solution

Marks spam silently (no error message shown to sender)

Fully customizable

Add this code to your child theme’s functions.php file.

Do not add it to your main theme’s functions.php, as the changes will be lost when the theme updates.

Here’s the snippet:

add_filter('wpcf7_spam', 'tgg_cf7_block_spam_phrases_silent');

function tgg_cf7_block_spam_phrases_silent($spam) {
$submission = WPCF7_Submission::get_instance();
if (!$submission) return $spam;
$data = $submission->get_posted_data();

$blocked_phrases = array(
'guest post',
'paid post',
'sponsored post',
'sponsor post',
'write for you',
'write for us',
'contribute post',
'submit article',
'submit guest post',
'backlink',
'back link',
'link building',
'link exchange',
'exchange link',
'seo link',
'do follow',
'dofollow',
'permanent link',
'insert link',
'add link',
'paid link',
'buy link',
'casino',
'gambling',
'betting',
'bitcoin',
'crypto'
);

foreach ($data as $value) {
if (!is_string($value)) continue;
foreach ($blocked_phrases as $phrase) {
if (stripos($value, $phrase) !== false) {
return true; // mark as spam silently
}
}
}
return $spam;
}

Leave a Reply

Your email address will not be published. Required fields are marked *