Jeff Barr's Blog

Things I Like..

Blocking Trackback Spam Using WordPress 1.2

Every day I get a number of trackback spams that I have to delete manually as part of my morning email processing ritual.

This morning I got tired of doing so, and put a quick hack into WordPress to block trackbacks which contain the most common words. This took just a minute, and I think it will make a difference.

The code works for WordPress 1.2 (I have not had the time to upgrade to 1.5 yet). The modifications are in wp-trackback.php . Simply open up this file, and add the new lines as shown in bold, below. This is at line 25 in my copy of the code.

…… if (empty($title) && empty($tb_url) && empty($blog_name)) { // If it doesn’t look like a trackback at all… header(‘Location: ‘ . get_permalink($tb_id)); } // Trackback spam if ((strstr($excerpt, “casino”) !== false) || (strstr($excerpt, “poker”) !== false) || (strstr($excerpt, “phentermine”) !== false)) { header(“Location: ” . get_permalink($tb_id)); } if ((strlen(”.$tb_id)) && (empty($_GET[‘__mode’])) && (strlen(”.$tb_url))) { ……

Be careful not to disturb anything else, and save the file. That’s all you need to do. If new types of trackbacks (with different subjects) start to appear, isolate the appropriate word and plug it in. The safest way to do this is to copy the line which contains the test for ‘poker’, paste it immediately following the original line, and adding the new “bad word”.