• Resolved Thomas Jarvis

    (@thomasjarvisdesign)


    Since upgrading the site to WordPress 5.9

    When using the solution below to only load JS and CSS on pages with contact forms:
    https://contactform7.com/loading-javascript-and-stylesheet-only-when-it-is-necessary/

    I am seeing a console error on all contact form pages

    https://www.thinkjarvis.co.uk/contact/

    wpcf7 JQuery Not Defined Error. Showing in the Console:
    /wp-content/plugins/contact-form-7/includes/js/index.js?ver=5.5.4

    Please can you advise?

    I Have Honeypot for CF7 and Flamingo installed. Disabling these plugins makes no difference

    Code added to contact template file:

    if ( function_exists( 'wpcf7_enqueue_scripts' ) ) {
            wpcf7_enqueue_scripts();
        }
     
        if ( function_exists( 'wpcf7_enqueue_styles' ) ) {
            wpcf7_enqueue_styles();
        }

    Code added to functions.php in child theme:

    // Disable Contact Form 7 Unless Called
    add_filter( 'wpcf7_load_js', '__return_false' );
    add_filter( 'wpcf7_load_css', '__return_false' );
    • This topic was modified 3 years, 1 month ago by Thomas Jarvis. Reason: More detail added for debug
    • This topic was modified 3 years, 1 month ago by Thomas Jarvis.
    • This topic was modified 3 years, 1 month ago by Thomas Jarvis.

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter Thomas Jarvis

    (@thomasjarvisdesign)

    This problem was also reported here without a solution:
    https://www.ads-software.com/support/topic/js-error-wpcf7-is-not-defined/ The issue is the same. But without the Multistep plugin enabled.

    Thread Starter Thomas Jarvis

    (@thomasjarvisdesign)

    This solution works: But if you can provide an update to the documentation on the website it would br really appreciated.

    ‘function contactform7_dequeue_scripts() {
    $check_cf7 = false;

    if( is_page(‘contact’) ) {
    $check_cf7 = true;
    }

    if( !$check_cf7 ) {
    wp_dequeue_script( ‘contact-form-7’ );
    wp_dequeue_style( ‘contact-form-7’ );
    }
    }
    add_action( ‘wp_enqueue_scripts’, ‘contactform7_dequeue_scripts’, 77 );’

    I was having the same issue, thanks for the fix @thomasjarvisdesign

    Thread Starter Thomas Jarvis

    (@thomasjarvisdesign)

    @screenres No problem. Feel sorry for me I had to roll this fix out to 60 websites manually….

    YOu can change the if is page to an array if you want to include multiple pages.

    I also added dequeue for contact form 7 conditional fields plugin.

    // Function to enable CF7 on certain pages
    function contactform7_dequeue_scripts() {
        $check_cf7 = false;
    
        if( is_page ( array ('contact', 'contact-us', 'pre-booking-form') ) ) {
            $check_cf7 = true;
        }
    
        if( !$check_cf7 ) {
            wp_dequeue_script( 'contact-form-7' );
            wp_dequeue_style( 'contact-form-7' );
            wp_dequeue_script( 'wpcf7cf-scripts' );
            wp_dequeue_style( 'cf7cf-style' );
        }
    }
    add_action( 'wp_enqueue_scripts', 'contactform7_dequeue_scripts', 77 );

    @thomasjarvisdesign 60 sites!
    Thankfully I haven’t got that many to update.
    CF7 Condition Fields still worked fine for me with the standard method but suppose I should keep it all neat in one call in one place.
    Thanks for the updated.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Bug: wpcf7 JQuery Not Defined Error’ is closed to new replies.