Besides using anti spam plugin akismet, another perfect way to defend your site from spammers is to create math challenge which is easy to do and no plugin required. Like the common anti spam or quiz this math challenge also gives interface that require active interaction of commenters (human). By providing this tool for your wordpress site, it will filter comments made by spambots because this math challenge preserve challenge that only human solvable.
The other benefit is, this math challenge anti spam does not need plugin which is absolutely important to keep your blog performance runs smooth, stable and of course load faster. Here, we're going to hack your wordpress engine by adding a little php codes. It takes only two easy steps, add the code to wp-comment-post.php and comment.php.
Well, it's easy, right? Another unique benefit of this anti spam is the math question will not ask administrator (in logged on mode) to solve a question, it will appears and give the math question only to your visitor. Do you care to cut your plugin use? Read also Minify HTML, Javascript and CSS without Plugin or try to recognize wordpress default code to help you hack your wordpress easily in Automatic Post Teaser without Plugin.
The other benefit is, this math challenge anti spam does not need plugin which is absolutely important to keep your blog performance runs smooth, stable and of course load faster. Here, we're going to hack your wordpress engine by adding a little php codes. It takes only two easy steps, add the code to wp-comment-post.php and comment.php.
- Open your comments.php file in your theme directory, find the following codes <input name="submit" type="submit" id="submit" value=" " so on so forth (it might not be the same but won't be much different). Then add the following code after it:
<?php if (!$user_ID) : ?>
The code will shows math question interface like 2 + 1 = ?. So you may also put the code somewhere else in your theme. Untill then, the math question should work and appears on your site, it will appear with a question on your comment box.
<?php $aaa=rand(0,5); $bbb=rand(3,9); ?><?php echo $aaa; ?>+<?php echo $bbb; ?>=
<input type="text" name="subab" id="subab" size="2" tabindex="5" style="width:20px" /><?php if ($req) _e('(Are You Human!)'); ?>
<input name="aaa" value="<?php echo $aaa; ?>" type="hidden" />
<input name="bbb" value="<?php echo $bbb; ?>" type="hidden" />
<?php endif; ?>
Well, it's quite fine to scarry commenters (human) and intimidate them to fill the answer of the quiz. But actually the function will not work properly, even if commenters put the wrong answer, the comments would still trash your blog. Hicks... - Now, in order to work properly open wp-comments-post.php file in your blog root directory. Find this code:
if ( '' == $comment_content )
Copy the code below and put it right after it, you're done.
wp_die( __('Error: please type a comment.') );
//Math Challenge anti spam Start
The function of the second code is to verify the answer of math question created earlier. In case commenters forgot or gave the wrong answer, wordpress will block comments untill the math question correctly answered.
if ( !$user->ID ) {
$aaa = trim($_POST[aaa]);
$bbb = trim($_POST[bbb]);
$subab = trim($_POST[subab]);
if((($aaa+$bbb)!=$subab)|| empty($subab)){
wp_die( __('Sorry, wrong answer. Please go back and try again!') );
}
}
//Math Challenge anti spam End
Well, it's easy, right? Another unique benefit of this anti spam is the math question will not ask administrator (in logged on mode) to solve a question, it will appears and give the math question only to your visitor. Do you care to cut your plugin use? Read also Minify HTML, Javascript and CSS without Plugin or try to recognize wordpress default code to help you hack your wordpress easily in Automatic Post Teaser without Plugin.