Skip to content

Instantly share code, notes, and snippets.

@robertdevore
Last active August 29, 2015 14:27
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 robertdevore/cfbc2a0286a92042ae8f to your computer and use it in GitHub Desktop.
Save robertdevore/cfbc2a0286a92042ae8f to your computer and use it in GitHub Desktop.
Only load Contact Form 7 scripts when the post/page uses the shortcode
<?php
/**
* Contact Form 7
* Speed enhancement
*
* The code below checks for the use of the CF7 shortcode and will remove scripts and styles when it isn't being used
*/
function deviodigital_deregister_contact_form() {
global $post;
if ( ! has_shortcode( $post->post_content, 'contact-form-7' ) ) {
remove_action('wp_enqueue_scripts', 'wpcf7_enqueue_styles');
remove_action('wp_enqueue_scripts', 'wpcf7_enqueue_scripts');
}
}
add_action( 'wp', 'deviodigital_deregister_contact_form');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment