How to Load scripts,styles and recatcha v3 only when needed
-
For people that will only load scripts,styles and recaptcha v3 on pages or post where the form is, try some like this code in your
functions.php
file:function contactform_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_script('google-recaptcha'); wp_dequeue_style( 'contact-form-7' ); } } add_action( 'wp_enqueue_scripts', 'contactform_dequeue_scripts', 99 );
- The topic ‘How to Load scripts,styles and recatcha v3 only when needed’ is closed to new replies.