Javascript Loads on Every Page
-
Hi there,
Great plugin — I recently started using it and am very pleased with the results. Just a couple of requests and suggestions, though.
1) Javascript loads on all pages, instead of only on pages where a form that uses conditional logic is placed. Would it be possible to add a setting to choose where the conditional logic js loads? I imagine giving users the choice between an exclude or include condition would be the best option, since some people like myself will only want to include the logic on a few pages, while others might only want to exclude the logic on a few pages. I’m currently editing plugin files to control where the javascript loads by placing an is_page condition before the call to enqueue_script, but obviously this isn’t ideal since I will have to reinsert my changes every time the plugin updates. Here is my code:
add_action('wpcf7_contact_form', 'wpcf7cf_enqueue_scripts', 10, 1); function wpcf7cf_enqueue_scripts(WPCF7_ContactForm $cf7form) { if (is_admin()) return; if ( is_page ( 'ID' ) ) { wp_enqueue_script('wpcf7cf-scripts', plugins_url('js/wpcf7cfscripts.js', __FILE__), array('jquery'), WPCF7CF_VERSION, true); } }
2) Also, you’ll notice that I changed the js file name, which leads to my second request of giving the file a unique name, instead of just scripts.js. In my experience, this can lead to problems if other plugins use the same file name. I may be wrong about that, but I figured it couldn’t hurt to bring it up…
3) Lastly, I tried minifying the javascript, but the conditional fields all become visible and conditional logic stops working. I’m not sure if there would be a way to serve minified javascript that actually works? Right now I’m thinking it doesn’t work because of the dependency on jquery, and from what I’ve seen in the past, minified jquery never works, so I’m thinking this isn’t possible, but again, thought I may as well ask.
Thank you very much for your help with this!
The page I need help with: [log in to see the link]
- The topic ‘Javascript Loads on Every Page’ is closed to new replies.