• Resolved 0wordpress0user0

    (@0wordpress0user0)


    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/

    /* 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 to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Glen Don Mongaya

    (@glenwpcoder)

    Hello @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

    (@0wordpress0user0)

    Hello @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

    (@glenwpcoder)

    No problem @0wordpress0user0

    Thank You.

    Thread Starter 0wordpress0user0

    (@0wordpress0user0)

    Hi there

    I have noticed an issue/conflict with another plugin when testing things out (https://www.ads-software.com/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://www.ads-software.com/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

    (@glenwpcoder)

    Thread Starter 0wordpress0user0

    (@0wordpress0user0)

    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.