Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Only include (WordPress plugin) Contact Form 7's' javascript and CSS when needed. Be sure to change !is_page('contact') to the ID or slug of the pages you want to use the contact form on.
/* =BEGIN: Only include Contact Form 7 javascript and CSS when needed
Source: http://fredrikmalmgren.com/only-include-contact-form-7-javascript-and-css-when-needed/
---------------------------------------------------------------------------------------------------- */
add_action( 'wp_print_scripts', 'deregister_cf7_javascript', 100 );
function deregister_cf7_javascript() {
if ( !is_page('contact') ) {
wp_deregister_script( 'contact-form-7' );
}
}
add_action( 'wp_print_styles', 'deregister_cf7_styles', 100 );
function deregister_cf7_styles() {
if ( !is_page('contact') ) {
wp_deregister_style( 'contact-form-7' );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment