Snippet: Load Contact Form 7 javascripts where required

Add following snippet to “functions.php”

Snippet

add_action('wp_footer','wpds_deenqueue_scripts',1);
function wpds_deenqueue_scripts() {
	wp_dequeue_script( 'jquery-form' );
	wp_dequeue_script( 'contact-form-7' );
}
add_action('wp_footer','wpds_print_scripts');
function wpds_print_scripts() {
	global $wpcf7;
	if(($wpcf7->global_unit_count>0 || $wpcf7->unit_count>0) ) {
		if(!wp_script_is( 'jquery-form', 'done' )) 
			wp_enqueue_script( 'jquery-form' );
		if(!wp_script_is( 'contact-form-7', 'done' )) 
			wp_enqueue_script( 'contact-form-7', wpcf7_plugin_url( 'scripts.js' ),
				array( 'jquery', 'jquery-form' ), WPCF7_VERSION, true );
	}
}

One Response to Snippet: Load Contact Form 7 javascripts where required

  1. Нaving гead this I believеԁ it wаs really infoгmativе.
    I аppгеciatе yοu ѕpending somе tіmе
    anԁ effort tο put this cοntent tοgethеr.
    I once аgain find myѕelf personally spеnding a lot of time
    bоth rеаdіng and commenting. But so ωhat, it was still woгthωhile!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>