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.

If you do not want to disable or remove reCAPTCHA badge then you can edit or restyle it that looks better. You can do that following this article:

How To Edit CSS of Google reCAPTCHA (Re-style, Change Position, Language, Resize reCAPTCHA Badge)?

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“.

Updated 2022: Remove Google reCAPTCHA for WordPress version 5.7+ and Contact Form version 5.4+ with code snippet:

function oiw_disable_recaptcha_badge_post(){
   if ( !is_single( array( '2021', '2022' ) ) ) {
      wp_dequeue_script('google-recaptcha');
      add_filter( 'wpcf7_load_js', '__return_false' );
      add_filter( 'wpcf7_load_css', '__return_false' );
      remove_action( 'wp_enqueue_scripts', 'wpcf7_recaptcha_enqueue_scripts', 20 );
   }
}
add_action( 'wp_enqueue_scripts', 'oiw_disable_recaptcha_badge_post' );

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 !




    9 Comments

  1. Good write ups. Many thanks. best online essay writer essay on how do i spend my summer vacation what website will write a paper for me

    Reply

  2. This does not work anymore. This is the new code, it will automaticly only display the badge on pages with the Contact Form 7 Shortcode in the Content:

    //reCaptcha V3 adjustments
    add_action( ‘wp_enqueue_scripts’, ‘gbol_remove_wpcf7_resources_if_no_contact_form’, 1 );
    function gbol_remove_wpcf7_resources_if_no_contact_form() {
    global $post, $gbol_css_dependencies, $abcf7;

    if ( isset( $post ) && is_singular() && has_shortcode( $post->post_content, ‘contact-form-7’ ) ) {
    return;
    }

    add_filter( ‘wpcf7_load_js’, ‘__return_false’ );
    add_filter( ‘wpcf7_load_css’, ‘__return_false’ );
    remove_action( ‘wp_enqueue_scripts’, ‘wpcf7_recaptcha_enqueue_scripts’, 20 );
    }

    Thanks go to Gal Baras
    Source: https://wordpress.org/support/topic/recaptcha-badge-on-all-pages-not-just-pages-with-contact-forms/page/9/

    Reply

  3. Thank you! It worked. Is it possible to move the badge to the top of the page? The badge is not totally visible when I scrolled down. The badge dissapears behind the footer.

    Reply

    • Jens,

      Sorry, it’s late when get back to you. You can use this snippet to move the badge to the top of the page + visible problem:


      bottom: 200px !important;
      opacity: .9;
      z-index: 999;

      Reply

  4. 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

Get $100 Free from Vultr to accelerate your website and application Register a Domain Name on Namesilo


Categories