Tag: contactform7

  • Contact Form 7: Ecco come disabilitarlo (tranne che sulla pagina di contatto)

    Contact Form 7: Ecco come disabilitarlo (tranne che sulla pagina di contatto)

    Contact Form 7 rimane, a mio parere, il miglior contact form per WordPress (qui una demo: Contattami).

    Unica pecca è che carica js, css ed eventuali extra (come il recaptcha) su tutto il sito (home, articoli, pagine extra).

    Per risolvere io uso questo snippet di codice (dentro la directory mu-plugins) che si direbbe funzioni in modo ottimale:

    <?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
        }
    }

go to top (svg)