Skip to content

Instantly share code, notes, and snippets.

@spirokovac

spirokovac/php Secret

Last active July 14, 2019 09:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spirokovac/33f791e153a03af75bf614e37097af15 to your computer and use it in GitHub Desktop.
Save spirokovac/33f791e153a03af75bf614e37097af15 to your computer and use it in GitHub Desktop.
Stop Contact Form 7 from loading on all WordPress site pages but selected one or selected ones in array.
function wps_contact_form_7_check_dequeue() {
//Set to false to be able to check against something
$check_cf7 = false;
// Page ID, title, slug, or array of such.
// if ( is_page( array( 37, 'contact-us', 'Contact US' ) ) ) {
// if ( is_page( 'contact-us' ) ) {
if ( is_page( array( 213, 'contact', 'Sample Page' ) ) ) {
$check_cf7 = true;
}
//so therefore dequeue only if is false
if ( !$check_cf7 ) {
wp_dequeue_script ( 'contact-form-7' );
wp_dequeue_style ( 'contact-form-7' );
}
}
add_action( 'wp_enqueue_scripts', 'wps_contact_form_7_check_dequeue', 77 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment