Last active
August 29, 2015 13:57
-
-
Save dannyconnolly/9811743 to your computer and use it in GitHub Desktop.
Only load contact form 7 scripts when needed in wordpress
This file contains hidden or 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
/** | |
* Only load contact form 7 script when needed | |
*/ | |
function cf7_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_style( 'contact-form-7' ); | |
} | |
} | |
add_action( 'wp_enqueue_scripts', 'cf7_dequeue_scripts', 99 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment