• Resolved honoluluman

    (@honoluluman)


    Hello and thank you for this great plugin.

    I have used this code related with the plugin Contact Form 7 to load JavaScripts and stylesheets of the plugin only when it is necessary. However adding as a snippet i am getting a console error ”wpcf7 is not defined” which means that the snippet and the CF are not working properly.

    I tried to change the priority of the snippet to 999 but still the same error. Any ideas why this is happening? https://prnt.sc/k0aoy9IFrJ5V

    Thank you for your input.

Viewing 1 replies (of 1 total)
  • Plugin Contributor Verdi Heinz

    (@ver3)

    Hi @honoluluman,

    Thanks for reaching out, and I’m glad you’re enjoying the plugin, thank you! 🙏

    The issue you’re experiencing with the “wpcf7 is not defined” error typically occurs when the required JavaScript for Contact Form 7 hasn’t been loaded before it’s needed. This might be happening because the snippet is running too late in the page load process, or the way it’s being enqueued could be causing a delay in loading the necessary scripts.

    Here are a couple of things you can try to resolve the issue:

    1. Ensure Correct Placement: Make sure that the wpcf7_enqueue_scripts() and wpcf7_enqueue_styles() functions are placed before wp_head() in your template. These functions need to be called early to ensure the necessary scripts are loaded in time.
    2. Modify the Snippet Priority: Instead of setting the priority to 999, try setting it earlier (like 10). This ensures that the snippet runs before the Contact Form 7 script is needed.
    3. Conditional Check for CF7: If you’re using the snippet on pages where Contact Form 7 isn’t present, you could add a conditional check to ensure the scripts are only enqueued when CF7 is on the page, something like this:

      if ( is_page( 'Contact' ) && function_exists( 'wpcf7_enqueue_scripts' ) ) { wpcf7_enqueue_scripts(); wpcf7_enqueue_styles(); }

    This way, you’re explicitly loading the necessary scripts only on the page that contains the form.

    Let me know if this helps or if you need further assistance!

Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.