Fix "Uncaught ReferenceError: captainform_preload_form_popup is not defined"

Written by Dan Mossop

Are your CaptainForms not working, or are you seeing "Uncaught ReferenceError: captainform_preload_form_popup is not defined" in your website's console? This error can disrupt the functionality of your site's features, such as accordions or tabs that suddenly refuse to work. Fortunately, this issue is resolvable, most commonly associated with conflicts arising from script deferral in caching and optimization plugins like WP Rocket.

Resolve the "Uncaught ReferenceError: captainform_preload_form_popup" error by:

  1. Temporarily disabling WP Rocket to check if errors stop.
  2. If resolved, exclude 'captainform-form-popup.js' from WP Rocket's script deferral.
  3. Clear cache and verify if site features work without error.

Understanding the Error

The error indicates that the browser is attempting to call a function from the CaptainForm plugin before the function has been loaded and defined in the global scope. This scenario is common when JavaScript scripts are deferred in order to improve the loading times of web pages.

WP Rocket Configuration

If you are using WP Rocket, then to resolve the JavaScript error, you'll often need to adjust the settings of your caching plugin to ensure the necessary scripts are not deferred. Here are the steps to fine-tune WP Rocket:

Troubleshoot with WP Rocket Disabled:

Temporarily disable WP Rocket on your website. By doing so, you check if script deferral is the cause of the issue. If the error vanishes and the Captain Forms on your site start work correctly, you've found the culprit.

Exclude Scripts from Deferral:

Rather than keeping WP Rocket disabled (which could impact your site's performance), you can tell WP Rocket to exclude the CaptainForm script from being deferred. To do this, you'll need to:

  • Access WP Rocket's settings in your WordPress admin panel.
  • Navigate to the File Optimization tab.
  • Scroll to the JavaScript section where you have the option to defer JavaScript files.
  • Add the name of the JavaScript file – captainform-form-popup.js – to the exclusion list.

This exclusion ensures the script loads in the correct order, allowing the CaptainForm’s functions to define before any attempts to use them. Consult WP Rocket's documentation for detailed guidance: Exclude files from Load JavaScript Deferred.

Verify the Results:

After making these changes, clear your site’s cache and browser cache. Then verify that the site is functioning correctly with no errors in the console.

Script deferral is a powerful speed optimization, but occasionally, it may need tweaking to play nicely with all your plugins. By following these steps, you'll be able to enjoy both the speed advantages of WP Rocket and the full functionality of the CaptainForm plugin.

Supercharge Your Posts with AI-Generated CTAs

Transform your WordPress site with WP Magic CTAs. Customize call-to-actions for each post to increase engagement effortlessly. Perfect for resolving site issues like script errors and optimizing your posts.

About Dan Mossop

Dan is a Scottish-born web developer, now living in Brisbane with his wife and son. He has been sharing tips and helping users with Divi since 2014. He created Divi Booster, the first Divi plugin, and continues to develop it along with 20+ other Divi plugins. Dan has a PhD in Computer Science, a background in web security and likes a lot of stuff, 

0 Comments

Submit a Comment

Comments are manually moderated and approved at the time they are answered. A preview is shown while pending but may disappear if your are cookies cleared - don't worry though, the comment is still in the queue.

Your email address will not be published. Required fields are marked *.

We may earn a commission when you visit links on our website.

Latest From Divi Booster

Enable Automatic Looping for YouTube Videos in the Divi Video Module

Enabling automatic looping for YouTube videos in your Divi video module ensures that content plays seamlessly and continuously without interruption. This feature can enhance user engagement, highlight key information, or create dynamic visual effects on your website....

Hide Video Controls in Divi Video Module

Disabling YouTube video controls in the Divi Video Module helps create a seamless, distraction-free viewing experience for your site visitors. This approach is useful when you want full control over how your video content appears and is interacted with on the page, or...

Mute YouTube Videos by Default in the Divi Video Module

In the Divi Video Module, starting your YouTube videos muted by default can create a more user-friendly browsing experience on your webpage. It is particularly beneficial for reducing distractions, enhancing visitor engagement, and providing a seamless content preview...

Autoplay Videos in Divi Video Module

Enabling videos in your Divi video module to start playing automatically can enhance both the site's design and user engagement. To ensure full compatibility with browser requirements, such as Chrome's autoplay policy, it's often necessary to start your videos muted...

How to Add the Post Status in Divi's Dynamic Content

Divi's Dynamic Content feature is great for enhancing your post/page templates with post-specific information. While Divi includes an option to show information such as the Post Created Date using Dynamic Content, there is no equivalent option for the Post Status....

Random Divi Posts