Created
August 29, 2018 17:24
-
-
Save walterebert/7ae9902cb8f139e4c45997a4715aca3e to your computer and use it in GitHub Desktop.
WordPress: Only load JS + CSS if a Contact Form 7 form is used
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function customize_cf7_dequeue() { | |
wp_dequeue_script( 'contact-form-7' ); | |
wp_dequeue_style( 'contact-form-7' ); | |
} | |
add_action( 'wp_enqueue_scripts', 'customize_cf7_dequeue' ); | |
function customize_cf7_enqueue( $content ) { | |
if ( has_shortcode( $content, 'contact-form-7' ) ) { | |
wpcf7_enqueue_styles(); | |
wpcf7_enqueue_scripts(); | |
} | |
return $content; | |
} | |
add_filter( 'the_content', 'customize_cf7_enqueue' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment