Shoora
2/12/2018 - 12:37 PM

Remove Contact Form 7 Scripts and Stlyes

Remove Contact Form 7 Scripts and Stlyes

<?php 
//You can set the value of this constant in your wp-config.php like this:
define('WPCF7_LOAD_JS', false);

//Likewise, you can control the loading of the CSS stylesheet with WPCF7_LOAD_CSS. Contact Form 7 does not load the CSS stylesheet when the value of WPCF7_LOAD_CSS is false (default: true). You can set it in the wp-config.php like this:
define('WPCF7_LOAD_CSS', false);

//Or, you can also disable the loading of the JavaScript and CSS by adding a few lines of code into your theme’s functions.php file, like this:
add_filter( 'wpcf7_load_js', '__return_false' );
add_filter( 'wpcf7_load_css', '__return_false' );

// And then load it only where the form is used. 
// Note that wpcf7_enqueue_scripts() and wpcf7_enqueue_styles() must be called before wp_head() is called.
    if ( function_exists( 'wpcf7_enqueue_scripts' ) ) {
        wpcf7_enqueue_scripts();
    }
 
    if ( function_exists( 'wpcf7_enqueue_styles' ) ) {
        wpcf7_enqueue_styles();
    }
// source: https://contactform7.com/loading-javascript-and-stylesheet-only-when-it-is-necessary/
?>