Skip to content

Instantly share code, notes, and snippets.

@wpexplorer
Created October 9, 2016 17:04
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 wpexplorer/cc4bb9757d44fa55a5d4dfe3de9c8552 to your computer and use it in GitHub Desktop.
Save wpexplorer/cc4bb9757d44fa55a5d4dfe3de9c8552 to your computer and use it in GitHub Desktop.
Contact from 7 conditionally load scripts
<?php
/**
* Contat Form 7 Configuration Class
*
* @package Total WordPress Theme
* @subpackage 3rd Party
* @version 3.6.0
*/
if ( ! class_exists( 'WPEX_Contact_Form_7' ) ) {
class WPEX_Contact_Form_7 {
/**
* Start things up
*
* @version 3.6.0
*/
public function __construct() {
// Remove CSS Completely - theme adds styles
add_filter( 'wpcf7_load_css', '__return_false' );
// Remove JS
add_filter( 'wpcf7_load_js', '__return_false' );
// Conditionally load JS
add_action( 'wpcf7_contact_form', array( 'WPEX_Contact_Form_7', 'enqueue_js' ) );
}
/**
* Load JS conditionally
*
* @version 3.6.0
*/
public static function enqueue_js() {
if ( function_exists( 'wpcf7_enqueue_scripts' ) ) {
wpcf7_enqueue_scripts();
}
}
}
}
new WPEX_Contact_Form_7();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment