Disable Google reCAPTCHA for all pages Except specific page like Contact Page or Submit Form with Contact Form 7

Disable reCAPTCHA (v3) for all pages Except the one like Contact Page or Submit Form with Contact Form 7-min
Last updated on

Recently, Contact Form 7 (CF7) update has caused the Google reCAPTCHA invisible reCAPTCHA logo to show up on all pages in your WordPress.  We will help you disable it on every page except which pages you want to show up like contact page or submit form.

1. Disable Google reCAPTCHA v3 for all pages and Google’s Term, Policy

According to Google’s terms, if we disable or remove  Google reCAPTHA v3 badge for all pages, the validation will not occur. Because Google recommend the reCAPTCHA script run on many pages that would be more accurate when determining whether visitors (human) or bots who working on your website.

By default, Google get reCAPTCHA script, logo displayed on every page on the bottom right of the screen. This is creating a bad experience for visitors. And your website speed will slow down a bit (reflect by PageSpeed score like Google PageSpeed Insight, GTMetrix, Pingdom…) because your blog will have to load additional 1 JavaScript library of reCAPTCHA from Google on every page. We think this shouldn’t, we should show it when necessary (on some pages).

To avoid Google’s Term and Policy violations due to disable reCAPTCHA script on every page, you can run it on some pages and add this just before the submit button of your form, page:

This site is protected by reCAPTCHA and the Google <a href=”https://policies.google.com/privacy”>Privacy Policy</a> and <a href=”https://policies.google.com/terms”>Terms of Service</a> apply.

2. Disable Google reCAPTCHA v3 for all pages except specific pages like Contact Page or Submit Form

If you are using the Contact Form 7 version <5.2.x, you can remove reCAPTCHA badge following these steps in our this article:

In this article, we guide you remove Google reCAPTCHA v3 badge on every page with Contact Form 7 version > 5.2.x.

Contact Form version 5.2

To do that. Firstly, you open the functions.php file of your theme (using File Manager or FTP Client). This file is locate in: /wp-content/themes/your-theme/ and add the following  snippet:

function oiw_disable_recaptcha_badge_page(){
   if ( !is_page( array( 'contact' ) ) ) {
       wp_dequeue_script('google-recaptcha');    
       wp_dequeue_script('wpcf7-recaptcha');
       wp_dequeue_style('wpcf7-recaptcha');
   }
}
add_action( 'wp_enqueue_scripts', 'oiw_disable_recaptcha_badge_page' );

3. Remove Google reCAPTCHA v3 for specific post in WordPress

However, you don’t want to disable reCAPTCHA badge for page but you want to remove it for post. To do this, you can use the snippet below:

function oiw_disable_recaptcha_badge_post(){
     if ( !is_single( array( '2020', '2021' ) ) ) {
          wp_dequeue_script('google-recaptcha');
          wp_dequeue_script('wpcf7-recaptcha');
          wp_dequeue_style('wpcf7-recaptcha');
     }
}
add_action( 'wp_enqueue_scripts', 'oiw_disable_recaptcha_badge_post' );

You need to replace “2020” and ‘2021’ in our code snippet with Post ID you want to remove Google reCAPTCHA for it. To find the Post ID you can go to Post tab from Admin Dashboard and  hover your mouse over the post you want to find the Post ID. You can find it in the bottom left-hand corner of the screen that contains the Post ID (see screenshot attached below):

Like the screenshot above the Post ID is the number that comes after the “post=” and before the “&action=edit“.

All done. That’s all you need to do to disable Google reCAPTCHA (v3) for all pages or post except some pages, post you want. If you need some helps please let us know then.




Post a Comment

Please keep in mind that all comments are read and moderation.
Your email address WILL NOT be published. Please DO NOT use keywords in the Real Name field. Thank you !




    2 Comments

  1. Dear! I try to add two page to white-list. But not working on Post Type (post id = 6245), only work on Page Type (post id = 1747). I dont know why. Help me

    function oiw_disable_recaptcha_badge_page(){
       if ( !is_page( array( 1747, 6245 ) ) ) {
           wp_dequeue_script('google-recaptcha');    
           wp_dequeue_script('wpcf7-recaptcha');
           wp_dequeue_style('wpcf7-recaptcha');
    	   remove_action( 'wp_enqueue_scripts', 'wpcf7_recaptcha_enqueue_scripts' );
       }
    }
    add_action( 'wp_enqueue_scripts', 'oiw_disable_recaptcha_badge_page' );
    
    Reply

    • Hooey,

      Now, you can find the solution for your problem (disable reCAPTCHA use Post ID) in our article (just updated in the section #3). Enjoy it!

      Reply

Stablehost Coupons - Best Hosting in 2018 Register a Domain Name on Namesilo