Title: Problem with plugins and CF7 custom function
Last modified: July 23, 2025

---

# Problem with plugins and CF7 custom function

 *  Resolved [honoluluman](https://wordpress.org/support/users/honoluluman/)
 * (@honoluluman)
 * [10 months, 1 week ago](https://wordpress.org/support/topic/problem-with-plugins-and-cf7-custom-function/)
 * Hello and thank you for this great plugin.
   I have used [this code](https://contactform7.com/loading-javascript-and-stylesheet-only-when-it-is-necessary/)
   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](https://prnt.sc/k0aoy9IFrJ5V)
   Thank you for your input.

Viewing 1 replies (of 1 total)

 *  Plugin Contributor [Verdi Heinz](https://wordpress.org/support/users/ver3/)
 * (@ver3)
 * [10 months ago](https://wordpress.org/support/topic/problem-with-plugins-and-cf7-custom-function/#post-18579549)
 * Hi [@honoluluman](https://wordpress.org/support/users/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)

The topic ‘Problem with plugins and CF7 custom function’ is closed to new replies.

 * ![](https://ps.w.org/code-snippets/assets/icon.svg?rev=2148878)
 * [Code Snippets](https://wordpress.org/plugins/code-snippets/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/code-snippets/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/code-snippets/)
 * [Active Topics](https://wordpress.org/support/plugin/code-snippets/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/code-snippets/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/code-snippets/reviews/)

## Tags

 * [contact-form](https://wordpress.org/support/topic-tag/contact-form/)
 * [filter](https://wordpress.org/support/topic-tag/filter/)

 * 1 reply
 * 2 participants
 * Last reply from: [Verdi Heinz](https://wordpress.org/support/users/ver3/)
 * Last activity: [10 months ago](https://wordpress.org/support/topic/problem-with-plugins-and-cf7-custom-function/#post-18579549)
 * Status: resolved