Last active
May 27, 2018 16:57
-
-
Save rickrduncan/a0a3e93236b0a99cbd9958c9f7a7ef14 to your computer and use it in GitHub Desktop.
WordPress code snippet to remove contact form 7 bloat. Please visit http://rickrduncan.com/pro/wordpress/deregister-cf7-scripts-styles for details.
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
<?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'); | |
} | |
} | |
} |
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
<?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 | |
} |
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
<?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