Skip to content

Instantly share code, notes, and snippets.

@deckerweb
Created January 28, 2013 21:47
Show Gist options
  • Save deckerweb/4659412 to your computer and use it in GitHub Desktop.
Save deckerweb/4659412 to your computer and use it in GitHub Desktop.
Contact Form 7 plugin: Clean up global scripts & styles.
<?php
add_action( 'wp_enqueue_scripts', 'ddw_cf7_cleanup' );
/**
* Contact Form 7 plugin: Cleanup global scripts & styles.
*
* @author David Decker - DECKERWEB
* @link http://deckerweb.de/twitter
*/
function ddw_cf7_cleanup() {
/** Dequeue globally enqueued scripts & styles */
wp_dequeue_script( 'contact-form-7' );
wp_dequeue_style( 'contact-form-7' );
/** Only enqueue stuff on the used page ID */
if ( is_page( '12' ) ) {
wp_enqueue_script( 'contact-form-7' );
wp_enqueue_style( 'contact-form-7' );
} // end if
} // end function
@cyberwani
Copy link

Above code will load only on specific page/post. Instead, use below code to load CF7 JS and CSS when content contains CF7 shortcodes. It will work with any post type.
https://gist.github.com/cyberwani/38f945007e83600ca0bf0bc48d99361b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment