custom-contact-forms icon indicating copy to clipboard operation
custom-contact-forms copied to clipboard

Loading javascript and stylesheet only when it is necessary

Open webspilka opened this issue 9 years ago • 4 comments

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?

webspilka avatar Sep 13 '15 14:09 webspilka

This is definitely possible but will require a bit of investigation. I'll report back.

tlovett1 avatar Sep 14 '15 15:09 tlovett1

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.

webstractions avatar Oct 09 '15 01:10 webstractions

+1 Would love to load the scripts only on pages where there is a form and in footer when possible.

jasperf avatar Nov 30 '15 03:11 jasperf

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.

chuckreynolds avatar May 25 '16 09:05 chuckreynolds