How to stop loading Contact Form 7 scripts and styles on every page

Are you frustrated with so many javascript and stylesheet files loading in your website? Or how about on every single page even when they are not needed? I know for myself, this irks the hell-out-of me when I see that. So this is how to stop Contact Form 7 scripts and styles from loading on every page.

Contact Form 7 Scripts and Styles on Every Page

With the complexity of websites, sometimes you cannot help but use a lot of scripts and styles. Even though you can cache and/or compress them, you want to limit what loads.

Scripts are the heaviest of files, and they do add a lot of load to a website. Speed is a factor nowadays, especially with Google. The faster your website, the better you will rank.

Contact Form 7

One of the most popular plugins in the WordPress realm, Contact Form 7 is one plugin that loads its scripts and styles on “every single page”. Frustrating for me, so I looked into solving this issue I had with it. Luckily, they have a solution for this right on their website…

This is a snippet from their page:

Contact Form 7 loads its JavaScript and CSS stylesheet on every page. You might think it would be redundant or wasteful, and want to load them only on those pages that contain contact forms. I understand the feeling, but there is a technical difficulty for a plugin in knowing whether the page contains contact forms or not at the start of loading.

The best thing I can do here is to let you go to their page and follow their quick tutorial. A warning though, it does include some code work involving your website’s theme files. If you plan to do this, and if it’s a third party theme you are using, I recommend creating a child theme. This will allow you to keep your theme up-to-date without losing your changes.

However, if your website is using your own theme, then you can go ahead and edit the files (and your WordPress config file) by following their tutorial.

BACK-UP YOUR SITE before making any file modifications!

Contact Form 7 Tutorial

Test Your Site’s Speed

Just for the fun and curiosity of it, take a quick snapshot of your site’s load times with at least a couple of online tools.

  • GTMetrix – https://gtmetrix.com
  • WebPageTest – https://www.webpagetest.org/

Make note of your scores, and then make your changes. Once done, check your load times again with the same online testing tools and then see how much of a difference it made.

Leave a Reply

Thank you for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Let's engage in a robust conversation.

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