Created
June 8, 2012 20:29
-
-
Save stevegrunwell/2897997 to your computer and use it in GitHub Desktop.
Remove Contact Form 7 scripts and styles through the WordPress action hook API
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
/** | |
* Remove Contact Form 7's scripts and styles without having to add anything to wp-config.php (as described | |
* in the CF7 docs) by using the wpcf7_enqueue_styles and wpcf7_enqueue_scripts actions that Takayuki was | |
* nice enough to include in includes/controller.php | |
* @link http://contactform7.com/loading-javascript-and-stylesheet-only-when-it-is-necessary/ | |
*/ | |
add_action( 'wpcf7_enqueue_styles', function() { wp_deregister_style( 'contact-form-7' ); } ); | |
add_action( 'wpcf7_enqueue_scripts', function() { wp_deregister_script( 'jquery-form' ); } ); |
I see this was written 7 years ago, does it still work? I need to deregister scripts then put them in my theme scripts.js file. Odd because @Dinath commented recently that it works, but I don't see a jquery-form.js script anywhere in the plugin folder
I can confirm that deregistering the styles works, but deregistering the script doesn't work. What does work is this:
Add this to the theme's functions.php file
add_filter( 'wpcf7_load_js', '__return_false' ); add_filter( 'wpcf7_load_css', '__return_false' );
Add this to the theme header.php, just above <?php get_header(); ?>
<?php
if (is_page('the_page_i_want_to_show_the_scripts_and_styles')) {
if ( function_exists( 'wpcf7_enqueue_scripts' ) ) {
wpcf7_enqueue_scripts();
}
if ( function_exists( 'wpcf7_enqueue_styles' ) ) {
wpcf7_enqueue_styles();
}
}
?>
Replace 'the_page_i_want_to_show_the_scripts_and_styles' with the page slug.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Working good ! Thank you. For adopters you might consider using conditions on page.