Optimize script & style load only when needed
-
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'); } } }
The topic ‘Optimize script & style load only when needed’ is closed to new replies.