How to load CF7 CSS & JS only when form is on the page

  contact-form-7, javascript, php, wordpress

I want to speed up my site. I want to load Contact form 7 css & js only when form is one the page. I found solutions for this but they are not 100% for me. Why? Because they are based on which page I am. I want to make it another way. I’m using gutenberg to create my site and I don’t know where the form will be. I could be on Contact page, on main page or on subpage in future. So my idea is load css & js only when the form is in page. Any page. So is it any way to do it? I was thinking about simple ACF Checkbox to do it. When user want to put CF7 shortcode/form he need to click checkbox for example Website have form. Maybe there’s more elegant way? Thanks for any help!

Source: Ask Javascript Questions

LEAVE A COMMENT