Skip to content

Instantly share code, notes, and snippets.

@Luisoncm
Created May 14, 2018 10:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Luisoncm/ec39f0ad2d461e335fb30d02a4d87a6a to your computer and use it in GitHub Desktop.
Save Luisoncm/ec39f0ad2d461e335fb30d02a4d87a6a to your computer and use it in GitHub Desktop.
<?php
/*
* Plugin Name: CF7 Optimization
* Version: 0.1
* Author: Luis Colomé
* Author URI: https://luiscolome.com
*/
// By default don't load the script o style sheet.
add_filter( 'wpcf7_load_js', '__return_false' );
add_filter( 'wpcf7_load_css', '__return_false' );
// We load the JS and CSS of CF7 just in the pages where there are forms.
function custom_contact_script_conditional_loading(){
// Edit page IDs here ( if you hace more than on page with forms => if( is_page( array (83, 'contact-business', 'test' ) ) ) )
if( is_page(83) ) {
if ( function_exists( 'wpcf7_enqueue_scripts' ) ) {
wpcf7_enqueue_scripts();
}
if ( function_exists( 'wpcf7_enqueue_styles' ) ) {
wpcf7_enqueue_styles();
}
}
}
add_action( 'wp_enqueue_scripts', 'custom_contact_script_conditional_loading' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment