Skip to content

Instantly share code, notes, and snippets.

@spirokovac

spirokovac/php Secret

Last active Jul 14, 2019
Embed
What would you like to do?
Stop loading of Contact Form 7 files on all blog posts unless there is a shortcode 'contact-form-7'
//Stop loading Contact From 7 CSS and Javascript on all pages.
if( is_singular () ) {
$post = get_post ();
if( has_shortcode( $post -> post_content, 'contact-form-7' ) ) {
$check_cf7 = true;
}
}
if( !$check_cf7 ) {
wp_dequeue_script( 'contact-form-7' );
wp_dequeue_style ( 'contact-form-7' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment