Load Contact Form 7 Scripts only in Contact page to increase GTmetrix score

Few days ago one of my client ask me helping to increase GTmetrix score. While checking I found Contact Form 7 script is loading in homepage and it is hampering the score. Though the Hompage doesn’t have Contact Form to show. To increase the score, it was wise to load the Contact Form 7 script to load only in Contact Page.

To solve this issue I used this code which helps me the Contact Form 7 script not to load in Homepage, but only in Contact page where the form is used. Just use the code below in your theme’s function.php

function rankya_contactform7check_dequeue() {
	$check_cf7 = false;

	if( is_page('contact')) {
        	$check_cf7 = true;
    if( !$check_cf7 ) {
        wp_dequeue_script( 'contact-form-7' );
        wp_dequeue_style( 'contact-form-7' );
add_action( 'wp_enqueue_scripts', 'rankya_contactform7check_dequeue', 77 );

If you have any issue feel free to ask me question here in comments section
Contact me in Skype: om2000_cuet

2 thoughts on “Load Contact Form 7 Scripts only in Contact page to increase GTmetrix score”

  1. You helped me about a month back. Now I have a more complex problem that I have created and can’t figure out. I think I’m missing something about the overall flow of control.

    I’ve created a plugin the generates three slightly different forms. 1. for use in a popup (I’m using popup maker), 2. pretty much the same for but not using it a popup and 3. a contact for.

    Are you able to help me with this? if so, what is the best channel for you?



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s