• Resolved bluesky10

    (@jouielovesyou)


    functions.php

    
    function oiw_load_recaptcha_badge_page() {
    	if ( !is_page( array( 'contact' ) ) ) {
    wp_dequeue_script('google-recaptcha');
    }
    }
    add_action( 'wp_enqueue_scripts', 'oiw_load_recaptcha_badge_page' );
    
    // Deregister Contact Form 7 JavaScript files on all pages without a form
    add_action( 'wp_print_scripts', 'aa_deregister_javascript', 100 );
    function aa_deregister_javascript() {
    if ( ! is_page( 'contact' ) ) {
    wp_deregister_script( 'contact-form-7' );
    }
    }
    
Viewing 8 replies - 1 through 8 (of 8 total)
  • Thanks to both of you

    the CSS code doesnt work anymore ?

    i`m using this:

    .grecaptcha-badge {
    display: none;
    }

    you dont have to update the functions.php everytime your theme gets updated

    @alios24 The CSS simply does hides the badge after this loads on the front-end of the website whereas the code I have provided stops it from loading altogether from the beginning from the back-end of the website unless its the contact page ( assuming you only have one page with a form)

    Furthermore Contact Form 7 by default loads on every page as well. So if you want an extended code. use the following

    
    
    /* CONTACT FORM 7 */ 
    
    // Stop the CF7 CSS & JS FROM LOADING ON EVERY PAGE
    add_filter( 'wpcf7_load_js', '__return_false' );
    add_filter( 'wpcf7_load_css', '__return_false' );
    
    function disable_google_recaptcha_except_contact()
    {
        //Remove the captcha scripts if its not on the contact form
        if (!is_page(array( 'contact')) ) : 
            wp_dequeue_script('wpcf7-recaptcha');
            wp_dequeue_script('google-recaptcha');
        else : 
    
            // else if it is the contact form enqueue all the scripts related to CF7
            if (function_exists('wpcf7_enqueue_scripts')) {
    
                wpcf7_enqueue_scripts();
            }
    
            if (function_exists('wpcf7_enqueue_styles')) {
                wpcf7_enqueue_styles();
            }
      endif;
    
    }
    
    add_action('wp_enqueue_scripts', 'disable_google_recaptcha_except_contact');

    You can then further go about hiding the page on the contact form and simply stating at the bottom of the page you are using captcha :

    Full Details here: https://developers.google.com/recaptcha/docs/faq#id-like-to-hide-the-recaptcha-badge.-what-is-allowed

    • This reply was modified 4 years, 4 months ago by codenathan.

    oh, ok, i got it

    i`m using this CSS trick since V3 appeared

    the problem with adding code to the functions.php is that you have to add it everytime your theme gets updated (in my case ET Divi)

    @alios24 that’s where you are wrong, you can create child themes, the guys who made Divi created a post about it.

    https://www.elegantthemes.com/blog/divi-resources/divi-child-theme

    just create a child theme and have your own functions.php nothing else, you can even have your own style.css

    i know what child themes are, and i found its best you don`t make hundreds of modifications on a theme… for known reasons…

    simple CSS tricks for specific actions and thats it

    modifying themes are for the coders who dont have anything else to do

    i like out of the box software to deliver to my needs

    cheers.

    lol

    Thanks @codenathan very handy!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Protected by Recaptcha now Displayed on all Pages in the Latest Update’ is closed to new replies.