This is for all the users of Thesis theme with contact form 7 plugin.

If you’re using the contact form 7 Plugin on your blog, you would notice that it loads javascript on every page. You can use pingdom tool to perform a full-page test on your blog to test all elements on that page and find bottlenecks. When you test your site, you will notice that contact form plugin javascript loads when the homepage loads as well, which is not necessary – thus adding up to additional  page loading time.

To Reduce page loading time, a good way is to load the javascript of contact form 7 plugin on the actual contact page only.

Reduce Page Loading Time By Optimizing Contact Form 7 Plugin

All you need to do is, add the below code to your custom_functions.php file.

/* Adds in scripts for contact form 7 */
    remove_action('wp_print_scripts', 'wpcf7_enqueue_scripts' ); // Removes the scripts from loading on all pages for CF 7
    add_action('thesis_hook_footer','new_cf7_scripts'); // Adds back in the scripts on the appropriate page
function new_cf7_scripts() {
    if (is_page(array('contact','another-page'))) { // Change the name to match the name(s) of the pages using the form ?>
    <script src="<?php bloginfo('home'); ?>/wp-content/plugins/contact-form-7/jquery.form.js" type="text/javascript"></script>
    <script src="<?php bloginfo('home'); ?>/wp-content/plugins/contact-form-7/scripts.js" type="text/javascript"></script>
<?php } }

After adding this code to your custom_functions.php file you can test your site again at pingdom and you will notice that it does not load the contact page javascript while loading the homepage or any other page on your blog.

Do let us know what you think of this Thesis Hack to reduce you’re blogs loading time. We would like to thank Andrew Norcross for this hack.

Note – This is based on Thesis v1.8