Title: loading javascript and stylesheet only when it is necessary/
Last modified: September 3, 2020

---

# loading javascript and stylesheet only when it is necessary/

 *  Resolved [0wordpress0user0](https://wordpress.org/support/users/0wordpress0user0/)
 * (@0wordpress0user0)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/loading-javascript-and-stylesheet-only-when-it-is-necessary-4/)
 * The CSS and JS loads for all Contact Form 7 forms, what is the best way to have
   the plugin CSS and JS only load for specific forms/pages just like Contact Form
   7 does at [https://contactform7.com/loading-javascript-and-stylesheet-only-when-it-is-necessary/](https://contactform7.com/loading-javascript-and-stylesheet-only-when-it-is-necessary/)
 * /* Dequeue Scripts and Styles START */
    function disable_scripts_styles() { //
   if this is not the page, remove the script if( ! is_page(‘page-name’) ){ wp_dequeue_style(‘
   dnd-upload-cf7-css’);
 *  wp_dequeue_script(‘codedropz-uploader-js’);
    wp_dequeue_script(‘dnd-upload-cf7-
   js-extra’); wp_dequeue_script(‘dnd-upload-cf7-js’);
 *  }
    }
 * // adjust priority to make sure this runs after the plugins add their scripts/
   styles
    add_action(‘wp_enqueue_scripts’,’disable_scripts_styles’, 100); /* Dequeue
   Scripts and Styles END */
 * Using a similar logic one could use this?
 * remove_action( ‘wpcf7_enqueue_scripts’, ‘dnd_cf7_scripts’, 10 );
 * Neither of these 2 examples seem to work. Any help/pointers will be appreciated.
   Thanks!
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Floading-javascript-and-stylesheet-only-when-it-is-necessary-4%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Plugin Author [Glen Don Mongaya](https://wordpress.org/support/users/glenwpcoder/)
 * (@glenwpcoder)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/loading-javascript-and-stylesheet-only-when-it-is-necessary-4/#post-13355767)
 * Hello [@0wordpress0user0](https://wordpress.org/support/users/0wordpress0user0/),
 * Can you try this?
 *     ```
       add_action('wpcf7_enqueue_scripts', function(){
   
       	// Remove JS if the page is not contact form.
       	if( ! is_page('contact') ) {
   
       		// remove js script
       		wp_dequeue_script('codedropz-uploader');
       		wp_dequeue_script('dnd-upload-cf7');
   
       		// remove plugin style
       		wp_dequeue_style('dnd-upload-cf7');
       	}
   
       }, 100);
       ```
   
 * Let me know if that will work.
 * Thanks.
 *  Thread Starter [0wordpress0user0](https://wordpress.org/support/users/0wordpress0user0/)
 * (@0wordpress0user0)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/loading-javascript-and-stylesheet-only-when-it-is-necessary-4/#post-13356610)
 * Hello [@glenwpcoder](https://wordpress.org/support/users/glenwpcoder/)
 * Appreciate your prompt response. Thanks!
 * I tried the code you provided and it works, nice!
 * I am going to do some additional testing that the plugin meets my needs and I
   will be purchasing the PRO version soon thereafter.
 * Thanks again for all your help!
 *  Plugin Author [Glen Don Mongaya](https://wordpress.org/support/users/glenwpcoder/)
 * (@glenwpcoder)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/loading-javascript-and-stylesheet-only-when-it-is-necessary-4/#post-13358952)
 * No problem [@0wordpress0user0](https://wordpress.org/support/users/0wordpress0user0/)
 * Thank You.
 *  Thread Starter [0wordpress0user0](https://wordpress.org/support/users/0wordpress0user0/)
 * (@0wordpress0user0)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/loading-javascript-and-stylesheet-only-when-it-is-necessary-4/#post-13362488)
 * Hi there
 * I have noticed an issue/conflict with another plugin when testing things out (
   [https://wordpress.org/plugins/cf7-conditional-fields/](https://wordpress.org/plugins/cf7-conditional-fields/))
 * In my case the file upload input in a form is a **required** input but only if
   a certain option is selected. This is made possible with the plugin [https://wordpress.org/plugins/cf7-conditional-fields/](https://wordpress.org/plugins/cf7-conditional-fields/)
   and works fine before implementing the Drag and Drop upload plugin. The form 
   can be processed without the file upload but with the drag and drop plugin it’s
   not possible to submit the form without uploading a file even if certain conditions
   are not met. If I make the file upload not a required field then all is good.
 * So it seems when file upload input is marked a required input using *, it disregards
   the logic from the conditional fields plugin.
 *  Plugin Author [Glen Don Mongaya](https://wordpress.org/support/users/glenwpcoder/)
 * (@glenwpcoder)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/loading-javascript-and-stylesheet-only-when-it-is-necessary-4/#post-13363950)
 * [@0wordpress0user0](https://wordpress.org/support/users/0wordpress0user0/) , 
   please see this thread – [https://wordpress.org/support/topic/validation-issues-when-using-contact-form-7-conditional-fields/](https://wordpress.org/support/topic/validation-issues-when-using-contact-form-7-conditional-fields/)
 *  Thread Starter [0wordpress0user0](https://wordpress.org/support/users/0wordpress0user0/)
 * (@0wordpress0user0)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/loading-javascript-and-stylesheet-only-when-it-is-necessary-4/#post-13366757)
 * Thanks, this helpful and good to know. Is the requirement to name the Group and
   file name to be the same, as in the example, a requirement of Conditional fields
   plugin or the Drag and Drop plugin? My Group and file name are different and 
   posed no issue prior to using DnD plugin.
 * Separately, in the PRO version is it possible to have a custom upload folder 
   for each Contact Form 7 if one is using multiple forms to upload. For e.g. one
   form to receive files from clients and anther form for the admin to send files
   to clients.
 * Thanks for all your help, much appreciated!!

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘loading javascript and stylesheet only when it is necessary/’ is closed
to new replies.

 * ![](https://ps.w.org/drag-and-drop-multiple-file-upload-contact-form-7/assets/
   icon-128x128.jpg?rev=1984850)
 * [Drag and Drop Multiple File Upload for Contact Form 7](https://wordpress.org/plugins/drag-and-drop-multiple-file-upload-contact-form-7/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/drag-and-drop-multiple-file-upload-contact-form-7/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/drag-and-drop-multiple-file-upload-contact-form-7/)
 * [Active Topics](https://wordpress.org/support/plugin/drag-and-drop-multiple-file-upload-contact-form-7/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/drag-and-drop-multiple-file-upload-contact-form-7/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/drag-and-drop-multiple-file-upload-contact-form-7/reviews/)

 * 6 replies
 * 2 participants
 * Last reply from: [0wordpress0user0](https://wordpress.org/support/users/0wordpress0user0/)
 * Last activity: [5 years, 11 months ago](https://wordpress.org/support/topic/loading-javascript-and-stylesheet-only-when-it-is-necessary-4/#post-13366757)
 * Status: resolved