Here we will see how to remove Contact Form 7 plugin’s CSS and JS file to load except contact page.

Just put the code in your function.php file of the theme folder. Don’t forget to change the Contact page id in the code.

// Remove Contact Form 7 CSS + JS form all pages except Contact Page 
// Here put your contact page id instead of 12
add_action( 'wp_print_scripts', 'deregister_cf7_javascript', 15 );
function deregister_cf7_javascript() {
    if ( !is_page(12) ) {
        wp_deregister_script( 'contact-form-7' );
    }
}
add_action( 'wp_print_styles', 'deregister_cf7_styles', 15 );
function deregister_cf7_styles() {
    if ( !is_page(12) ) {
        wp_deregister_style( 'contact-form-7' );
    }
}
There are currently no comments.