Last active
August 29, 2015 14:27
-
-
Save robertdevore/cfbc2a0286a92042ae8f to your computer and use it in GitHub Desktop.
Only load Contact Form 7 scripts when the post/page uses the shortcode
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 | |
/** | |
* Contact Form 7 | |
* Speed enhancement | |
* | |
* The code below checks for the use of the CF7 shortcode and will remove scripts and styles when it isn't being used | |
*/ | |
function deviodigital_deregister_contact_form() { | |
global $post; | |
if ( ! has_shortcode( $post->post_content, 'contact-form-7' ) ) { | |
remove_action('wp_enqueue_scripts', 'wpcf7_enqueue_styles'); | |
remove_action('wp_enqueue_scripts', 'wpcf7_enqueue_scripts'); | |
} | |
} | |
add_action( 'wp', 'deviodigital_deregister_contact_form'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment