Results 1 to 5 of 5

Threaded View

  1. #1
    ddm
    ddm is offline Former Member
    Join Date
    July 2006
    Posts
    1,118
    Thanks
    418
    Thanked 470 Times in 287 Posts

    Default wordpress speed hacks - [for Contact form 7 plugin users]

    What: Stop cf7 enqueing CSS and JS on pages with no contact forms (seems like something the plugin author should have done, right?.. )

    Why: Cos of site speed. Google site health is a thing now. every millisecond for page load and render is critical. less scripts / kludge = faster site, happy google, happy users.

    How: put this code in your theme or child theme functions.php

    Code:
    function rjs_lwp_contactform_css_js() {
        global $post;
        if( is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, 'contact-form-7') ) {
            wp_enqueue_script('contact-form-7');
             wp_enqueue_style('contact-form-7');
    
    
        }else{
            wp_dequeue_script( 'contact-form-7' );
            wp_dequeue_style( 'contact-form-7' );
        }
    }
    add_action( 'wp_enqueue_scripts', 'rjs_lwp_contactform_css_js');
    hopefully saves some of ye some milliseconds

  2. The Following 4 Users Say Thank You to ddm For This Useful Post:

    DaftDog (13 August 2020), drifter8 (13 August 2020), PromoteCasino (12 August 2020), vardan (13 August 2020)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •