Skip to content

Instantly share code, notes, and snippets.

@spirokovac

spirokovac/php Secret

Last active July 14, 2019 09:21
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 spirokovac/32b3ebbe3ddeb1ea5ab949f90e7c1578 to your computer and use it in GitHub Desktop.
Save spirokovac/32b3ebbe3ddeb1ea5ab949f90e7c1578 to your computer and use it in GitHub Desktop.
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