• Resolved dukeo

    (@dukeo)


    The code displayed there doesn’t work anymore: https://contactform7.com/loading-javascript-and-stylesheet-only-when-it-is-necessary/

    Despite having these 2 lines in my functions.php file:

    add_filter( 'wpcf7_load_js', '__return_false' );
    add_filter( 'wpcf7_load_css', '__return_false' );

    The following code is still added on every single page of my website:

    <script src='***/wp-content/plugins/wpcf7-recaptcha/assets/js/wpcf7-recaptcha-controls.js?ver=1.2' id='wpcf7-recaptcha-controls-js'></script><script id='google-recaptcha-js-extra'>
    var wpcf7iqfix = {"recaptcha_empty":"Please verify that you are not a robot.","response_err":"wpcf7-recaptcha: Could not verify reCaptcha response."};
    </script><script src='https://www.google.com/recaptcha/api.js?hl=en_US&onload=recaptchaCallback&render=explicit&ver=2.0' id='google-recaptcha-js'></script>

    Unless I’m wrong, it looks like you added a hotfix for a different issue and this extra code doesn’t check if the variables are set to disable the code or not.

    How can I disable the integration sitewide and include the code only on pages I want to?

Viewing 1 replies (of 1 total)
  • Thread Starter dukeo

    (@dukeo)

    Nevermind, I found the fix. If anyone else is having this issue, paste the following code in the functions.php file of your WordPress theme:

    add_action( 'wp_enqueue_scripts', 'wps_deregister_scripts', 100 );
    function wps_deregister_scripts() {
    	if ( !is_page('contact') ) {
    		wp_dequeue_script( 'google-recaptcha' );
    	}
    }

    Please note that if the slug of your contact page isn’t “contact”, you will need to edit the 3rd line.

Viewing 1 replies (of 1 total)
  • The topic ‘Disable CF7 integration, except on Contact page’ is closed to new replies.