Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Takayuki Miyoshi

    (@takayukister)

    Thread Starter jt70

    (@jt70)

    Thanks Takayuki,

    I found another method that doesn’t entail changing any plugin files, and modified the code a bit. I just insert this once into my theme functions.php. I’m not really a coder but can normally make a few tweaks to get something basic to work. What do you think?
    I like it because I can combine it with multiple plugins and should work with plugin updates.
    JT70

    // DEREGISTER PLUGIN EVENTS
    function dvk_dequeue_scripts() {
    
        $load_scripts = false;
    
        if( is_singular() ) {
    
            $post = get_post();
    
            if( has_shortcode($post->post_content, 'contact-form-7') ) {
    
                $load_scripts = true;
    
            }
    
        }
    
        if( ! $load_scripts ) {
    
            wp_dequeue_script( 'contact-form-7' );
    
            wp_dequeue_style( 'contact-form-7' );
    
        }
    
        $load_poll_scripts = false;
    
        if( is_singular() ) {
    
            $post = get_post();
    
            if( has_shortcode($post->post_content, 'poll') || has_shortcode( get_post_meta( get_the_ID(), 'YOUR_FIELD_ID', true ), 'poll' ) ) {
    
                $load_poll_scripts = true;
    
            }
    
        }
    
        if( ! $load_poll_scripts ) {
    
            wp_dequeue_script( 'wp-polls' );
    
            wp_dequeue_style( 'wp-polls' );
    
        }
    
    }
    
    add_action( 'wp_enqueue_scripts', 'dvk_dequeue_scripts', 99 );
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Speeding up site-why load css/js on all pages?’ is closed to new replies.