reCaptcha Archives - PluginsForWP https://plugins-for-wp.world/blog/tag/recaptcha/ Premium WordPress Plugins And Themes For An Affordable Price Wed, 08 Jun 2022 15:28:14 +0000 en-US hourly 1 https://wordpress.org/?v=6.8.3 https://plugins-for-wp.world/wp-content/uploads/2020/01/cropped-Pluginsforwp-Favicon-32x32.jpg reCaptcha Archives - PluginsForWP https://plugins-for-wp.world/blog/tag/recaptcha/ 32 32 How to Add reCaptcha to WordPress Comments to Prevent Spam Comments https://plugins-for-wp.world/blog/add-recaptcha-to-wordpress-comments/ https://plugins-for-wp.world/blog/add-recaptcha-to-wordpress-comments/#comments Thu, 24 Jun 2021 15:25:31 +0000 https://plugins-for-wp.world/?p=378192 Spam comments on your blog posts will clog up your database and email account with false notifications. Believe us; we know all about it here. For months we received hundreds of spam comments every day. Luckily, we solve the problem by adding a reCaptcha box to the comments form. This article will teach you how […]

The post How to Add reCaptcha to WordPress Comments to Prevent Spam Comments appeared first on PluginsForWP.

]]>
Spam comments on your blog posts will clog up your database and email account with false notifications. Believe us; we know all about it here.

For months we received hundreds of spam comments every day. Luckily, we solve the problem by adding a reCaptcha box to the comments form.

This article will teach you how to add reCaptcha to your WordPress comment form to prevent spam messages.

What is Google reCaptcha?

reCaptcha is the box added to the form above the submit button and asking the user to prove that they are not a robot.

They are widespread and come in different verification options:

The most used one is the ‘I’m not a robot‘ checkmark, just like this one (that’s the one we use).

I am not a robot box

On the other hand, another popular one is proving that you are not a robot by selecting specific images from the same group as cars.

Select images

reCAPTCHA uses an advanced risk analysis engine and adaptive challenges to keep malicious software from engaging in abusive activities on your website. Meanwhile, legitimate users will be able to login, make purchases, view pages, or create accounts and fake users will be blocked.

Official Google reCaptcha website

Google reCaptcha Types

There are two versions of Google reCaptcha.

reCaptcha v2 – the box that appears inside the form (comments, login, register, etc.). They are the examples I showed you above, which is the version we will use in this tutorial.

The user will need to solve a challenge before submitting the form.

reCaptcha v3 – added to every page (or chosen pages) on your website and will analyze your behavior as a visitor. Human users act differently from bots (dah!!) and, therefore, be legit. It will be blocked if a robot tries to leave a comment or review.

reCaptcha v3

We only want to add a reCaptcha box to the WordPress comments form specifically instead of all pages. Therefore, we will use the reCaptcha v2 type.

Why Use reCaptcha?

As mentioned above, spam comments are not fun and can damage your website or admin’s experience.

Furthermore, spam comments will take space on your database and, if not deleted frequently, will clog and slow it down.

Also, if you get an email notification (like we do) for every comment left on your website, it will pile up quickly. That will slow down your workflow and keep you from focusing on critical emails.

Spam notification

We often skipped valuable comments left by legit users because we assumed they were spam comments. It doesn’t happen anymore after adding the reCaptcha form to our website.

Before we added the reCaptcha feature, we had two options, constantly delete all the comments or turn off WordPress comments altogether, and we didn’t want to do that.

After enabling the reCaptcha option, all comments are legit and approved when receiving comments.

Add reCaptcha to WordPress Comment Form

We can add reCaptcha in two different ways. The first way is by installing a plugin, and the second way is by using a PHP function. In this tutorial, we will cover both methods.

Regardless of your option, we will first need to generate our reCaptcha API keys.

Generate reCaptcha API Keys

Open the Google reCaptcha website and click the v3 Admin Console link to generate the keys.

Google reCaptcha website

Then, click on reCaptcha v2 and select the ‘I’m not a robot’ checkbox option. Enter your website’s domain name, accept the terms of service and click submit.

generate reCaptcha keys

You’ll have both the public and secret API keys on the next screen. Keep this window open, and we will need to copy them shortly.

reCaptcha API Keys

We can now move on to the second step and use the keys with a plugin or a function.

Add reCaptcha With a Plugin

The first way to add reCaptcha to your website is by using a plugin. First, from inside your WordPress dashboard, navigate to Plugins -> Add New, and install the reCaptcha by BestWebSoft plugin.

add reCaptcha with a plugin

Once activated, navigate to reCaptcha -> Settings, choose Version 2 and enter your site and secret keys generated on the last step.

Then, choose the forms you would like to enable reCaptcha for and scroll to the bottom of the page to save the changes.

reCaptcha plugin settings

Once saved, visit one of your blog posts, scroll to the comments section and see the added reCaptcha box.

reCaptcha was added to WordPress comment form

Follow the section below if you want to use a function instead of a plugin.

Add reCaptcha With a Function

We will use a PHP function to integrate reCaptcha with the comments form with this method.

First, navigate to Appearance -> Theme Editor and open the single.php (or singular.php) file of your child theme. Alternatively, you can also access the files by creating an FTP account.

If you don’t have a child theme yet, create one after reading how to make a WordPress child theme article.

Tip: please backup your website before editing core files.

Then, copy the code below and paste it just before the get_header(); function in the single.php file and click save.

wp_enqueue_script('google-recaptcha', 'https://www.google.com/recaptcha/api.js');

Once saved, open the functions.php file, scroll to the bottom of it, and paste the code below:

/* Add Google recaptcha to WordPress comment box */
function add_google_recaptcha($submit_field) {
    $submit_field['submit_field'] = '<div class="g-recaptcha" data-sitekey="enter_your_site_key_here"></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' => 'enter_your_secret_key_here',
                            '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');
}

Make sure to replace ‘enter_your_site_key_here‘ and ‘enter_your_secret_key_here‘ with the actual keys, we generated earlier. Once replaced, click save.

Finally, visit the comments section on one of your blog posts and verify that the reCaptcha box was added successfully. Go ahead and test the box by leaving a comment.

Conclusion

In this article, you learned how to add a reCaptcha box to WordPress comments in two different ways.

Leave us a comment and tell us which one of the methods you chose to perform this task.

The post How to Add reCaptcha to WordPress Comments to Prevent Spam Comments appeared first on PluginsForWP.

]]>
https://plugins-for-wp.world/blog/add-recaptcha-to-wordpress-comments/feed/ 3
How To Add reCaptcha To Contact Form 7 (v3) https://plugins-for-wp.world/blog/recaptcha-with-contact-form-7/ https://plugins-for-wp.world/blog/recaptcha-with-contact-form-7/#respond Mon, 28 Dec 2020 16:50:18 +0000 https://plugins-for-wp.world/?p=142065 reCaptcha is an anti-spam tool by Google that prevents websites from receiving automatic messages from bots. Contact Form 7 is one of the most popular form plugins for WordPress used by millions around the world. In this article, you’ll learn how to integrate reCaptcha with Contact Form 7 on your WordPress website. What Is reCaptcha […]

The post How To Add reCaptcha To Contact Form 7 (v3) appeared first on PluginsForWP.

]]>
reCaptcha is an anti-spam tool by Google that prevents websites from receiving automatic messages from bots.

Contact Form 7 is one of the most popular form plugins for WordPress used by millions around the world.

In this article, you’ll learn how to integrate reCaptcha with Contact Form 7 on your WordPress website.

What Is reCaptcha

Bots and malicious software uses websites’ forms to send messages or leave comments with abusive content or spam.

Often, the left content will damage your domain score, hurt the visitors’ experience, and decrease the overall quality of your website.

reCaptcha is a free service created by Google to help protect your website against that.

The service adds a test box that is very easy for humans to solve but very hard for bots.

reCaptcha demo

When adding a reCaptcha to a contact form, you minimize the number of spam messages and guarantee a better user experience.

Integrate reCaptcha With Contact Form 7

To integrate between reCaptcha and CF7 you’ll first need to install the plugin, then get the unique keys for your domain name, and finally, connect between the two.

Step #1: Install Contact Form 7

From your WordPress dashboard, navigate to Plugins -> Add New. Then, search and install the Contact Form 7 plugin.

Contact Form 7 WordPress Plugin

Once you activated the plugin, move forward and get the API keys.

Step #2: Generate reCaptcha keys

To start using this tool, you’ll need to have a Google account and get the API keys for your domain name.

Open the official reCaptcha website and click on the Admin Console.

reCaptcha Admin Console

Fill the form with your information such as label, type, domain, and etc, and click submit.

Get reCaptcha Keys

Copy both site and secret keys from the next page.

reCaptcha site and secret keys

After getting both keys, we can go back to our WordPress website.

Step #3: Connect the keys

In this step, we will paste the keys inside the CF7 integration screen.

First, navigate to Contact -> Integration.

Then, click on setup integration and enter the keys you generated in the last step.

Contact Form 7 reCaptcha integration

Once pasted, you will see the message that reCaptcha is active on your site.

reCaptcha is active with CF7

In the last step, we need to verify that we successfully added the reCaptcha box to our website.

Step #4: Test the form

After entering the reCaptcha keys into the Contact Form 7 settings page, we need to verify that it’s working and active on our website.

Thus, visit your website or the page you’re displaying the contact form 7 on and look for the reCaptcha logo at the bottom right corner.

reCaptcha is active on WordPress website

If you see the logo, it means that you connected between the two successfully and your form is now secured.

That’s it, the two are now integrated together and you won’t get any spam messages any longer.

Related Articles

Conclusion

In this article, you learned how to integrate Google reCaptcha with Contact Form 7 to secure your forms.

Leave us a comment and let us know if you have any questions about the process.

The post How To Add reCaptcha To Contact Form 7 (v3) appeared first on PluginsForWP.

]]>
https://plugins-for-wp.world/blog/recaptcha-with-contact-form-7/feed/ 0