tlovett1 / custom-contact-forms

Build beautiful custom forms and manage submissions the WordPress way.
https://taylorlovett.com
163 stars 50 forks source link

Loading javascript and stylesheet only when it is necessary #166

Open webspilka opened 9 years ago

webspilka commented 9 years ago

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?

tlovett1 commented 9 years ago

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

webstractions commented 9 years ago

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.

jasperf commented 8 years ago

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

chuckreynolds commented 8 years ago

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.