Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WordPress code snippet to remove contact form 7 bloat. Please visit http://rickrduncan.com/pro/wordpress/deregister-cf7-scripts-styles for details.
<?php
//* Do NOT include the opening php tag above
/**
*
* Remove Contact Form 7 CSS stylesheet from all pages except where needed.
*
*/
add_action('wp_print_styles', 'rrd_remove_cf7_css');
function rrd_remove_cf7_css() {
if ( function_exists( 'wpcf7_enqueue_styles' ) ) {
if ( !is_page('contact')) { //replace the slug if needed
wp_deregister_style('contact-form-7');
}
}
}
<?php
//* Do NOT include the opening php tag above
if( is_page( array( 'contact', 'contact-us', 'contact-others' ) ) {
//either contact or contact-us page is in view
}
else {
//all other pages in view
}
<?php
//* Do NOT include the opening php tag above
/**
*
* Remove Contact Form 7 js file from all pages except where needed.
*
*/
add_action('wp_print_scripts', 'rrd_remove_cf7_js');
function rrd_remove_cf7_js() {
if ( function_exists( 'wpcf7_enqueue_scripts' ) ) {
if ( !is_page('contact')) { //replace the slug if needed
wp_deregister_script('contact-form-7');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.