Skip to content

Instantly share code, notes, and snippets.

@mrfoxtalbot
Created February 12, 2018 12:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrfoxtalbot/891fb3413fac95c3d8bed5a0ea725d94 to your computer and use it in GitHub Desktop.
Save mrfoxtalbot/891fb3413fac95c3d8bed5a0ea725d94 to your computer and use it in GitHub Desktop.
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/
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment