Skip to content

Instantly share code, notes, and snippets.

@samkent
Last active August 29, 2015 14:14
Show Gist options
  • Save samkent/a418f98f1ea91407e098 to your computer and use it in GitHub Desktop.
Save samkent/a418f98f1ea91407e098 to your computer and use it in GitHub Desktop.
WordPress Contact Form 7 only enqueue if page.
/**
* Contact Form 7 only enqueue if page
*
* @author Sam Kent
* @link http://www.samkent.com
*/
function contact_form_7_cleanup() {
// Dequeue scripts and styles
wp_dequeue_script( 'contact-form-7' );
wp_dequeue_style( 'contact-form-7' );
// Enqueue if page template
if ( is_page_template( 'contact.php' ) ) {
wp_enqueue_script( 'contact-form-7' );
wp_enqueue_style( 'contact-form-7' );
}
}
add_action( 'wp_enqueue_scripts', 'contact_form_7_cleanup' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment