Created
October 20, 2018 16:19
-
-
Save SHABU89/7afbe5b337cd5c4ca58f07b185c69fbc to your computer and use it in GitHub Desktop.
Contact Form 7 Scripts and Stylesheet files only add if shortcode present in the page else remove it.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function rjs_lwp_contactform_css_js() { | |
global $post; | |
if( is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, 'contact-form-7') ) { | |
wp_enqueue_script('contact-form-7'); | |
wp_enqueue_style('contact-form-7'); | |
}else{ | |
wp_dequeue_script( 'contact-form-7' ); | |
wp_dequeue_style( 'contact-form-7' ); | |
} | |
} | |
add_action( 'wp_enqueue_scripts', 'rjs_lwp_contactform_css_js'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for your comment. This won't work in your case if the shortcode present in the footer or widget the above function is only for the post content.