Last active
August 29, 2015 14:03
-
-
Save davidvandenbor/6a839a560c162b82631c to your computer and use it in GitHub Desktop.
WordPress: Prevent Contact 7 javascript and stylesheets from loading on EVERY page
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
| <?php | |
| /** | |
| * Prevent Contact Form 7 javascript and styles from loading on every page | |
| * Load them only on pages that contain the CF7 shortcode! | |
| * @author @david <david@davidvandenbor.nl> | |
| */ | |
| function david_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', 'david_dequeue_scripts', 99 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment