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 15 replies - 31 through 45 (of 53 total)
  • exinator4

    (@exinator4)

    Adding my voice to the conversation to say this is a regression. D:

    I used @florianziegler’s functions.php hack to get rid of the badge site-wide. (Thank you!)

    I really hope that at some point CF7 can be updated so that the badge is only displayed on a page where a CF7 form is shown! It seems a little bit excessive to have it all over the site otherwise…

    acurran

    (@acurran)

    It would be much better to go back to Really Simple Captcha instead of this really intrusive reCaptcha v3. As far as I can gather, Really Simple Captcha does not involve any external tracking and not a major overhead like reCaptcha v3 does. Ok it might not be as advanced but it is perfectly adequate for most purposes. Is there an option of using Really Simple Captcha instead of reCaptcha v3 in Contact Form 7?

    • This reply was modified 8 months ago by acurran.
    cag8f

    (@cag8f)

    @florianziegler and/or @larrydaniele are you still using the custom PHP code you mentioned in this post, and is it still working as expected? My CF7 form is on one single page, so I think your code may be a possible solution, if it is still working as expected.

    Thanks!

    Larry Daniele

    (@larrydaniele)

    @cag8f I’m still using the custom code on a number of sites and consider it a solution. I have not evaluated if just having this on pages with forms gives Google enough information about site visitors to effectively block the bad guys while letting through the good ones. But I’ve had no complaints about it, so I’m assuming it’s good enough.

    cag8f

    (@cag8f)

    @larrydaniele OK thanks for that. I’ll give the code a shot on my site.

    >> I have not evaluated if just having this on pages with forms gives Google enough information about site visitors to effectively block the bad guys while letting through the good ones. But I’ve had no complaints about it, so I’m assuming it’s good enough.

    Got it. I guess the proof is in the pudding, and really only noticed by the end user receiving the form submissions. In my case, I am that person, so i should hopefully be able to detect any noticeable difference in spam. Thanks again.

    edit: FYI On first glance, I am able to get @florianziegler’s code to work, without your modification. It seems to result in all recaptcha files being loaded on only my Contact page, which is the desired result. Not sure why that didn’t work for you.

    • This reply was modified 8 months ago by cag8f.
    Rejean

    (@rejeanlepage)

    The proposed solution @florianziegler and @larrydaniele is that
    you need to modify wp-content/plugins/contact-form-7/includes/functions.php
    and at the last line you add this code below…

    
    function my_register_cf7_js() {
        // Dequeue cf5 and recaptcha scripts, preventing them from loading everywhere
        add_filter( 'wpcf7_load_js', '__return_false' ); // Might as well use their filter
        wp_dequeue_script( 'google-recaptcha' );
    
        // If current post has cf7 shortcode, enqueue!
        global $post;
        if ( isset( $post->post_content ) AND has_shortcode( $post->post_content, 'contact-form-7' ) ) {
            if ( function_exists( 'wpcf7_enqueue_scripts' ) ) {
                wpcf7_enqueue_scripts();
                wp_enqueue_script( 'google-recaptcha' );
            }
        }
    }
    
    add_action( 'wp_enqueue_scripts', 'my_register_cf7_js', 20, 0 );
    

    My question is what will happen when Contact Form 7 is updated again? Will this functions.php file be updated and lost our modification ?
    Is there a custom/functions.php somewhere?
    Should this be added to CF7 next update?
    Can this me made an option or another plugin?

    thank you very much for this solution and all the help.

    • This reply was modified 7 months, 4 weeks ago by Rejean.

    @rejeanlepage, if you added the code within the file, wp-content/plugins/contact-form-7/includes/functions.php, it will be overwritten if you update the CF7 plugin. That code can be added into your theme functions.php or a separate custom plugin then it would “safe” on update, but you also would not be able to tell if a patch was created to resolve this issue. Solutions to issues like this is just personal preference. I added my solution to my theme functions.php and will test to see if it is still necessary after the next update of CF7.

    hello, I don’t know if it helps but I am using this plugin to block Recaptcha on pages where I don’t want it, and it seems to work well:
    https://wordpress.org/plugins/wp-asset-clean-up/

    (i’m not related to this plugin, just happy to have found it !)

    Thank @florianziegler and @rolturn for the right way to exclude google recaptcha via a function! If someone includes contact form 7 via ACF you will find a function here:
    https://support.advancedcustomfields.com/forums/topic/has_shortcode-not-detected/#post-76128

    @lonty
    Thank you. Your snippet helped me.

    • This reply was modified 7 months, 1 week ago by ArtakEVN.

    Hi All

    Great plugin but I too am a bit frustrated with seeing the badge on every page, especially on mobile devices. Any chance the developer with resolve this issue.
    Regards
    Dave.

    Thanks @catboulin for the link to the Asset CleanUp plugin (https://wordpress.org/plugins/wp-asset-clean-up/).

    A big +1 from me for this plugin for countering the inefficiencies of CF7 or any other plugin!

    Tim

    oh really it helped you also ? I am so happy to have found it after fighting with slow websites for years.

    For selective loading of Contact Form 7 or whatever other plugins you can do what @lonty explains, creating a function, or you can use the “Plugin Organizer” to load on specific pages specific plugins. Just remove Contact form 7 as a “global” plugin, go to you contact page and scrolling down you’ll see you can drag and drop (right to left) the contact form plugin to enabled plugins.
    NOTE: I’ll have to do this on each page where you have contact form and each language 😉
    Here you have a video explaining it: https://youtu.be/q5aXFa7cIpI

    • This reply was modified 5 months, 3 weeks ago by gtamborero.
    • This reply was modified 5 months, 3 weeks ago by gtamborero.
    • This reply was modified 5 months, 3 weeks ago by gtamborero.

    Plugin organizer is ridiculous compared to
    https://wordpress.org/plugins/wp-asset-clean-up

    Sorry to repeat, but I think that sometimes it’s good to help people as I wished someone helped me.

Viewing 15 replies - 31 through 45 (of 53 total)
  • You must be logged in to reply to this topic.