How To Disable Contact Form 7 Refill

Contact Form 7 is one of the most popular WordPress plugins on the market. With over 5 million active installations, it’s a power house. The plugin is 100% free and maintained by Takayuki Miyoshi. It is no wonder its a common choice for any website that needs a basic contact form.

However, recently, posts have been circulating around the internet suggesting that you should remove Contact Form 7 to improve your website’s performance. Contact Form 7 is arguably not the fastest plugin out of the box, but this is not because of its CSS or JavaScript files loading.

The issues with Contact Form 7 started circulating around July 2018 with a plugin update. The purpose of the update was to solve caching issues and the forms captcha feature. However, in conjunction with the release, users started scouring the forums to find a way to disable the refill functionality. Some went as far as editing the plugins’ code directly (I highly advise against doing this).

The list quite literally goes on and on with issues pertaining to the refill feature. Let’s explore the refill feature a bit. We will go over the who, what, and why of the refill feature. Lastly, I will show you how to disable the Contact Form 7 refill feature.

What Causes It To Use Refill?

The refill function only loads when you’re using some sort of page caching functionality. This is why if you are trying to debug a script while logged in, you never see the calls to it.

The purpose of the refill functionality is to prevent issues with the plugins captcha when making use of page caching. That is if you were using a dedicated caching plugin and the captcha built into Contact Form 7. The refill functionality is actually quite an intelligent fix. It is amazing at preventing mail from being lost. However, with tools such as Akismet, it might not be a good fit for all websites.

Furthermore, if you’re not using the captcha functionality, but you are caching your pages, this call will load multiple times on every page load. This can hammer your web server.

Yes, It’s Hurting My Server. What Do I Do?

The solution is so simple, that it is almost sad. It is easily missed if you only glanced over the code in Contact Form 7. To disable the refill feature in Contact From 7, you need to add custom JavaScript. To add the custom JavaScript, insert this code into a plugin like Insert Headers and Footers or into a custom JavaScript slot in your theme.

wpcf7.cached = 0; 

This small snippet of code tells Contact Form 7 that “X” page is not cached, so it does not need to load the refill functionality. Just make sure you’re loading this in the footer of your page and it should work without a hitch.

Note: After adding the code, you will need to clear your cache.

Closing Thoughts

One thing, that people tend to misunderstand about Contact Form 7 is they think it’s inherently slow. In fact, Contact Form 7 is one of the leanest contact form plugins on the market and that’s because it’s also one of the most basic contact form plugins.

The plugin has no builder, no giant CSS files, and no large JavaScript files. It’s just dumb with how it loads its files and it’s refill functionality is only as fast as your server.

scott hartley

About the author

Scott is a web performance geek, lover of all things coffee, and avid video game player. His WordPress work delves into web performance, web security, and SEO.

8 thoughts on “How To Disable Contact Form 7 Refill”

  1. Hi,
    Thanks for the information.
    Does “wpcf7.cached = 0;” merely fool CF7 to think the page is not cached when it is actually cached? If so, inherently, the conflict still exists does it not? .. now that there’s no ‘refill’ to cure it leading perhaps to captcha not working at all.

    And if we actually have to ‘not cache’ the page that would defeat the purpose of caching to increase speed times. Seems to us a ‘damned if you do, damned if you don’t’ scenario!

    One solution is to avoid having forms on the homepage (which is the subject of load time issues since it’s arguably the most visited) altogether – not ideal since it restricts the use of elements (sign up forms) that may help in sales funnel.

    Appreciate your thoughts on this.

    Appreciate your thoughts on this.

    • So, yes the code at it’s most basic level tells Contact Form 7 that the page is not cached because Contact Form 7 performs a check via /includes/controller.php around line 50 where if the wp_cache constant is defined as true then it will enable the refill. Contact Form 7 by default makes use of Recaptcha which doesn’t require the refill functionality to be enabled from my own testing as it’s purely JavaScript-driven. If you were using another plugin for captcha one that uses images the refill would attempt to regenerate the captcha on the cached page that way it would remain functioning (which isn’t required for ReCaptcha).

      I don’t typically make use of any captcha instead opting to integrate Contact Form 7 with Akismet which is just as effective in my testing (some spam gets through albeit not much), and you avoid the sheer amount of bloat that comes with using ReCaptcha.

      Hope this helps!

  2. Thanks for this. Tbh there should be a filter to disable the functionality. This does seem a bit dirty. 🙂

  3. I have a contact form with no spam protection. And I’m using Wp Super Cache. I disabled to refill request. Will I lose any CF7 emails if page has been cached for too long? I think if a page is cached for more than 24 hours, there could be an issue with form submission. Something to do with “nonce”?

  4. After using this code I get error in the browser’s console: “Uncaught ReferenceError: wpcf7 is not defined”
    Do You have ane cure for this?


Leave a Comment