Best way to organize scripts on my WP site
-
Hi All,
I am making a site and using simple javascript to control certain elements on my pages, formatting, animations etc. As the pages are different the scripts which work on one page will throw errors on another as the target elements are not there. I only know two solutions to this problem :1) Put conditions before calling all my functions if the target elements exist…
if($myElement.length){runMyFucntion()};
2) Otherwise create a separate page_template (tempalte_home, template_about etc.) for every page on my site, and only run the scripts I need on each template.Neither of these scenarios seems ideal to me, but my knowledge of javascript is not very advanced. Is there a better way? What is the recommended method of running different js scripts across pages on a WP site?
Thnks!!
- The topic ‘Best way to organize scripts on my WP site’ is closed to new replies.