Excluding Plugin Related File on Certain WordPress Page
By adding code snippets to your themes functions.php file you can remove the javascript and CSS from all pages that don’t use that particular wordpress plugin which makes your site load faster.
Here is an example for the Contact 7 form wordpress plugin. This snippet removes the JS files.
add_action( 'wp_print_scripts', 'deregister_cf7_javascript', 100 );
function deregister_cf7_javascript() {
if ( !is_page(100) ) {
wp_deregister_script( 'contact-form-7' );
}
}
Remove Contact 7 css files
add_action( 'wp_print_styles', 'deregister_cf7_styles', 100 );
function deregister_cf7_styles() {
if ( !is_page(100) ) {
wp_deregister_style( 'contact-form-7' );
}
}
In both code snippets, change the number 100 to the id of the page where you have added the contact form or use the page slug instead. Note you can change the !is_page to the inverse of is_page and then this would remove the files only from that particular page.





If you could email me with a few ideas on how you made your blog look this excellent, I would be thankful.