Removes JS, CSS, and AJAX behaviors from Contact Form 7

Removes JS, CSS, and AJAX behaviors from Contact Form 7 on child sites.

Snippet Type

Execute on Child Sites

Snippet

function wpcf7_custom_enqueue_scripts() {
	if ( is_plugin_active( 'contact-form-7/wp-contact-form-7.php' ) ) {
		wp_dequeue_script( 'wpcf7-recaptcha' );
		wp_dequeue_script( 'google-recaptcha' );
		wp_dequeue_style( 'contact-form-7' );
		global $post;
		if ( isset( $post->post_content ) && has_shortcode( $post->post_content, 'contact-form-7' ) ) {
			if ( function_exists( 'wpcf7_enqueue_scripts' ) ) {
				wpcf7_enqueue_scripts();
				wp_enqueue_script( 'wpcf7-recaptcha' );
				wp_enqueue_script( 'google-recaptcha' );
			}
			if ( function_exists( 'wpcf7_enqueue_styles' ) ) {
				wpcf7_enqueue_styles();
			}
		}
		$service = WPCF7_RECAPTCHA::get_instance();
		if ( ! $service->is_active() ) {
			return;
		}
		wp_add_inline_script( 'contact-form-7', 'wpcf7.cached = 0;', 'before' );
	}
}
add_filter( 'wpcf7_load_js', '__return_false' );
add_filter( 'wpcf7_load_css', '__return_false' );
add_action( 'wp_enqueue_scripts', 'wpcf7_custom_enqueue_scripts', 10000, 0 );

Reference

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.