Skip to content

Instantly share code, notes, and snippets.

@aj-adl
Last active June 22, 2018 02:08
Show Gist options
  • Save aj-adl/e3cdd06a19edab3ec959 to your computer and use it in GitHub Desktop.
Save aj-adl/e3cdd06a19edab3ec959 to your computer and use it in GitHub Desktop.
Intermediate CF7 example of Style/JS removal
<?php
// Make sure you only use opening / closing tags if needed!!!
// Removes Contact Form 7 scripts and Styles except on contact-us page
add_action( 'wp', 'BSHP_cf7_conditionally_load_assets_custom' );
// returns false, used for setting filters to false
function return_false() {
return false;
}
function BSHP_cf7_conditionally_load_assets_custom() {
// Any Number of conditional statments can go here ( using || for OR, && for AND )
if ( !is_page( 'contact-us') && !is_page( 46 ) &&!is_page_template( 'contact.php' ) {
add_filter( 'wpcf7_load_css', 'return_false' );
add_filter( 'wpcf7_load_js', 'return_false' );
}
}
// Make sure you only use opening / closing tags if needed!!!
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment