-
-
Save SalvatoreNoschese/4f56f2c2b44fed0d6b9a584088c82bd4 to your computer and use it in GitHub Desktop.
Mu-Plugins: Disable Contact Form 7 Assets Except on Contact Page
This file contains hidden or 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 | |
/** | |
* Plugin Name: Disable Contact Form 7 Assets Except on Contact Page | |
* Description: Disables Contact Form 7 assets (JavaScript, CSS, and reCaptcha) on all pages except the contact page. | |
* Version: 0.1 | |
* Author: Salvatore Noschese | |
* Author URI: https://salvatorenoschese.it/ | |
*/ | |
// Function to disable Contact Form 7 assets on all pages except the contact page | |
add_action( 'wp_enqueue_scripts', 'disable_cf7_assets_except_contact_page' ); | |
function disable_cf7_assets_except_contact_page(){ | |
if ( !is_page('contattami') ) { // Check if it's not the contact page | |
add_filter( 'wpcf7_load_js', '__return_false' ); // Disable loading CF7 JavaScript | |
add_filter( 'wpcf7_load_css', '__return_false' ); // Disable loading CF7 CSS | |
remove_action( 'wp_enqueue_scripts', 'wpcf7_recaptcha_enqueue_scripts', 20 ); // Disable loading CF7 reCaptcha script | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment