Hi @esyagentur
All the JavaScript is loaded in the footer, so it won’t block the rendering of any of your page content. You could still defer it with a plugin like Autoptimize if you like, which also allows you to defer all your CSS except for above-the-fold styles.
Thanks,
Angus
Hi Gus,
thanks for support.
There is only one CSS part blocking rendering – css/cf7-material-design.css
We only use cf7 on two pages, so we load js and css only on those pages. Can you provide code snippet similar to the following snippet for function.php?
?php
if ( function_exists( ‘wpcf7_enqueue_scripts’ ) ) {
wpcf7_enqueue_scripts();
}
if ( function_exists( ‘wpcf7_enqueue_styles’ ) ) {
wpcf7_enqueue_styles();
}
?>
Thanks again.
Hi @esyagentur
Try this in your functions.php. It will dequeue all the plugin scripts and styles except on pages with slug ‘contact’ or ‘form’. Change the if condition to suit your pages.
function my_dequeue_cf7md_assets() {
if( ! is_page( 'contact' ) && ! is_page( 'form' ) ) {
wp_dequeue_script( 'md-components-js' );
wp_dequeue_script( 'autosize' );
wp_dequeue_script( 'cf7-material-design' );
wp_dequeue_style( 'cf7md_roboto' );
wp_dequeue_style( 'cf7-material-design' );
}
}
add_action( 'wp_enqueue_scripts', 'my_dequeue_cf7md_assets', 20 );
Thanks,
Angus
Awesome – works perfect.
Thanks a lot.