Quantcast
Channel: WordPress.org Forums » All Topics
Viewing all articles
Browse latest Browse all 59525

Optimize script & style load only when needed

$
0
0

Replies: 0

Hi, did find really helpful to optimize and easy to optimize script & style load this way.
It seems odd not to have an option on the plugin itself to do it…


add_action('wp_print_scripts', 'my_remove_cf7_js');
function my_remove_cf7_js() {
if ( function_exists( 'wpcf7_enqueue_scripts' ) ) {
        global $post;
        if(!has_shortcode($post->post_content,'cf7-form') && !!has_shortcode($post->post_content,'contact-form-7') ){
	      wp_deregister_script('contact-form-7');
   		}	
	}
}
add_action('wp_print_styles', 'my_remove_cf7_css');
function my_remove_cf7_css() {
	if ( function_exists( 'wpcf7_enqueue_styles' ) ) {
		global $post;
        if(!has_shortcode($post->post_content,'cf7-form') && !!has_shortcode($post->post_content,'contact-form-7')){
            wp_deregister_style('contact-form-7');
   		}	
	}
}

Viewing all articles
Browse latest Browse all 59525

Trending Articles