custom-contact-forms
custom-contact-forms copied to clipboard
Loading javascript and stylesheet only when it is necessary
hi Do you have something similar to http://contactform7.com/loading-javascript-and-stylesheet-only-when-it-is-necessary/ ? I can not load scripts on pages where there is no form?
This is definitely possible but will require a bit of investigation. I'll report back.
I only use the CCF on one page in most cases. In my enqueue-functions.php file for the theme, I basically check to see if that page is the current one. If not, I will dequeue all scripts/css for CCF.
For ContactForm 7, similar, but I add the filters to return '__return_false' like in the link above.
This technique works for virtually all plugins in the wild. My dequeue/enqueue processing can get quite a bit involved, but worth the effort in the long run. For instance, I have a special slideshow script that runs on Project pages for the gallery section and it only gets enqueued if the post type is a project.
+1 Would love to load the scripts only on pages where there is a form and in footer when possible.
This thread seems old but FWIW... Forms > Settings
you can add the slug or post/page ID to restrict the header assets loading. Works well. Just implemented.