If you own a WordPress site then you would’ve faced some spammy comments on your site. Yes, they are very harmful and can hack your site. To prevent your site from spam comments and spammers you should add reCaptcha to WordPress site for better results and security.
But the question arises How to add Google reCaptcha in WordPress? If you have the same question, don’t worry because here, I will explain everything you need to know about reCaptcha and WordPress. So, just stay right till the end to clear all of your doubts.
Table of Contents
What Does reCaptcha Mean?
reCaptcha is a service that is provided by Google to ensure and protect websites from scams and abuses. reCaptcha uses an advanced risk analysis engine that helps identify whether the website or software is used by a human or is used by some robots to do some harm to the website.
reCaptcha uses the CAPTCHA system to identify humans and robots. The full form of CAPTCHA is a Completely Automated Public Turning test to Computers and Humans Apart. CAPTCHA system provides many challenges which are not very difficult for computers and are relatively easier for humans.
What is WordPress?
WordPress is a content management system used by people to create a website easily without even knowing anything about coding and just by some easy drag and drop. Some best affordable Web hosting for WordPress should be used to store the data of the website in the servers of the hosting. Some best and affordable themes for WordPress should also be used to give their audience a good look. And that’s it by some easy customizations and posting some content your website is ready in WordPress.
What is the Need to Add reCaptcha to WordPress?
People mostly prefer reCaptcha to prevent their sites from hackers. But there are many other reasons for using reCaptcha forms in the WordPress site. Some of them are listed below:
- reCaptcha protects your WordPress site by not letting any robots or hackers attacking your website.
- As the hackers try to hack your website by trying to login through using hundreds of passwords. So, Google reCaptcha doesn’t let them do their work as it stop brute force attacks.
- Stops some cyber criminals in their intension to comment in your site and take links from your site.
- Google reCaptcha is also use to make online transactions and shoppings more secure.
- It is also used in many ticket buying platforms so that the scammers couldn’t buy bulk tickets by the help of some bots.
How to Add reCaptcha to WordPress with the plugin?
Below are some of the steps which you need to follow to add WordPress google ReCaptcha to your site.
- First of all you need to login to your WordPress abministration panel by entering your admin username and password,
- In your dashboard you would see the plugin button click that and then click on Add New.
- In the upper right corner you would see a search box click on the search box and search for the plugin named Google Captcha.
- The Google Captcha plugin would appear on your screen and below there would be an option to install the plugin. Click that button and wait for it to get install.
- After the installation completed you need to activate the Google captcha plugin.
- Go to Plugin section, locate the Google Captcha plugin and then click on the settings button below.
- Now, you need to create a public and private key to use Google Captcha. For that you need to click the registration link under the Authentication button.
- After receiving the keys you need to enter the public key into the public key textbox and the private key to the private key textbox.
- Now just click save settings under the Options section.
- That’s it Captchas are now activate in your site. You can check it by just going to the comment section of any post on your site. There would be a captcha submission form.
How to Add reCaptcha to WordPress Without a Plugin?
Google Captcha is a free service and very easy to use. Below are some of the steps you need to follow if you wish to add reCaptcha to WordPress without a plugin.
- Visit https://www.google.com/recaptcha/admin#list and then you need to register your website.
- Copy and keep the site key and secret key appeared for further use.
- Go to the appearance option in your WordPress dashboard and then click on theme editor.
- Edit the single.php section from your theme option and add the code given below before the get_header();
wp_enqueue_script('google-recaptcha', 'https://www.google.com/recaptcha/api.js');
Now you need to edit the functions.php section. By adding the code given below with your site_key in line 5 and with your secret_key in line 15.
/**
* Google recaptcha add before the submit button
*/
function add_google_recaptcha($submit_field) {
$submit_field['submit_field'] = '<div class="g-recaptcha" data-sitekey="your_site_key"></div><br>' . $submit_field['submit_field'];
return $submit_field;
}
if (!is_user_logged_in()) {
add_filter('comment_form_defaults','add_google_recaptcha');
}
/**
* Google recaptcha check, validate and catch the spammer
*/
function is_valid_captcha($captcha) {
$captcha_postdata = http_build_query(array(
'secret' => 'your_secret_key',
'response' => $captcha,
'remoteip' => $_SERVER['REMOTE_ADDR']));
$captcha_opts = array('http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $captcha_postdata));
$captcha_context = stream_context_create($captcha_opts);
$captcha_response = json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify" , false , $captcha_context), true);
if ($captcha_response['success'])
return true;
else
return false;
}
function verify_google_recaptcha() {
$recaptcha = $_POST['g-recaptcha-response'];
if (empty($recaptcha))
wp_die( __("<b>ERROR:</b> please select <b>I'm not a robot!</b><p><a href='javascript:history.back()'>« Back</a></p>"));
else if (!is_valid_captcha($recaptcha))
wp_die( __("<b>Go away SPAMMER!</b>"));
}
if (!is_user_logged_in()) {
add_action('pre_comment_on_post', 'verify_google_recaptcha');
}
Code link:
https://www.oueta.com/wordpress/add-google-recaptcha-to-wordpress-comments-without-plugin/
Click on save settings and that’s it you have successfully added a reCaptcha to WordPress without plugin.
Conclusion
In this article, I have shared some important details about reCaptcha and Captcha. I have also shared the two ways using which you can add ReCaptcha to your WordPress site. If you don’t know anything about coding then I would recommend you to add the reCaptcha using the Google Captcha plugin. But if you are aware of a little bit of coding then you can also use the other method. But yes both of them are safe and simple and you won’t receive any problem using both methods.
FAQ’s
Google ReCaptcha plugin is the best WordPress reCaptcha plugin. It is used and trusted by thousands of people.
Some of the alternatives of Google reCaptcha are DataDome, Akamai Bot Manager, HUMAN, Reblaze, etc.
No, reCaptcha doesn’t have any effect on SEO. But try not to use reCaptcha unnecessarily because it can affect the user experience in your site.
You can use reCaptcha in any such situation where you want your user to input something in your site like comment section, contact us form, etc.
Google reCaptcha is totally free to use. You don’t need to pay a single penny to use Google reCaptcha.
Many site owners have got very good results after using Google reCaptcha. They are receiving very few spam comments after enabling reCaptcha. Yes, there is still some spamming going on so we can say that reCaptcha is 80-85% effective.