Created
December 18, 2012 19:59
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* =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