Support » Plugin: Contact Form 7 » reCaptcha badge on ALL pages, not just pages with Contact Forms!

  • I applied the one-line code fix to Contact Form 7 to make reCaptcha v3 work. I’ve got a single page on my site that uses Contact Form 7, but now I have the “protected by reCAPTCHA” badge on every single page and post on my site.

    That brings up two questions:

    1 – Can I have the badge only appear where it’s used?

    2 – Can I get Contact Form 7 to only touch pages/posts it’s used on? Integrating it everywhere, even where it’s not used at all, adds a bunch of unnecessary server-client interactions that only serve to extend page load times and slow my site down.

Viewing 10 replies - 46 through 55 (of 55 total)
  • Thanks! I’ll have a look at it! I read your post but thought that was a database cleaner 🙁 !

    The code below will make it so the badge only appears on pages with contact forms.
    1. add the code below to functions.php
    2. update your CF7 page name to the array in line 3.

    add_action('wp_print_scripts', function () {  
     //Add pages you want to allow to array
     if ( !is_page( array( 'contact','some-other-page-with-form' ) ) ){
      wp_dequeue_script( 'google-recaptcha' );
      //wp_dequeue_script( 'google-invisible-recaptcha' );
     }
    });

    source:https://wplearninglab.com/hide-recaptcha-v3-badge/

    • This reply was modified 8 months, 1 week ago by freqtwo.

    Hi, I used the code

    body:not(.page-id-XX) .grecaptcha-badge {
    display: none;
    }

    it worked well, but it doesn’t work for the mobile site. What do I use for the mobile site, so that the badge only shows on the mobile site?

    @larrydaniele and @florianziegler, thank you for your method of removing the recaptcha. While this does stop the Google recaptcha from loading, the code to stop CF7 scripts from loading wasn’t working for me:
    add_filter( 'wpcf7_load_js', '__return_false' );

    I’m guessing the load order of wp_enqueue_scripts comes after wpcf7_load_js, even adding a priority to the action. What I ended up doing is moving the wpcf7_load_js block outside of the function.

    For additional optimization, you can also disable CF7 css from loading and enqueue that only on pages with CF7 shortcode.

    Tobo

    (@infonetzlichtcom)

    @freqtwo So that is the solution for now? Is there maybe a better inetgration of recaptcha through contact form 7?

    Thanks :).

    Tobo

    (@infonetzlichtcom)

    1. It would be great if the ALL Contact Form 7 scripts only loading on pages where CF7 form is used.
    2. Instead of the “recaptcha badge” add the following under the “Send” button in different languages:
    This site is protected by reCAPTCHA and the Google
    Privacy Policy and
    Terms of Service apply.

    Would be awesome :)!

    Maybe here you will find a solution with everything you need.

    https://www.xcep.net/blog/contact-form-7-scripts-styles-and-recaptcha-only-on-certain-pages/

    Script, styles and recaptha are only loaded on pages, where the ‘contact-form-7’ shortcode is found.

    ctrlaltdelete

    (@ctrlaltdelete)

    This plugin is stupid i can’t believe the author don’t care!!!

    Gal Baras

    (@galbaras)

    If anyone’s interested, I’ve been able to disabled the inclusion of CF7 and reCAPTCHA resources on singular pages with no contact form like this:

    add_action( 'wp_enqueue_scripts', 'custom_load_contact_form_resources', 1 );
    function custom_load_contact_form_resources() {
    	global $post;
    
    	if ( isset( $post ) && is_singular() && has_shortcode( $post->post_content, 'contact-form-7' ) ) {
    		return;
    	}
    
    	remove_action( 'wp_enqueue_scripts', 'wpcf7_do_enqueue_scripts' );
    	remove_action( 'wp_enqueue_scripts', 'wpcf7_recaptcha_enqueue_scripts' );
    }

    This does NOT cover every option and the code goes in functions.php.

    gtamborero

    (@gtamborero)

    Great @galbaras ! I didn’t know that there was an easy way to find shortcodes on a post! : has_shortcode()

Viewing 10 replies - 46 through 55 (of 55 total)
  • You must be logged in to reply to this topic.