I'm new to WordPress, tried first searching for this and found a few related answers, none of which i fully understood. Will appreciate a few lines of concrete instructions. I have a WordPress page that has a script with a few functions and then another short script that uses them. I'd like to reuse these functions in some other pages. so:
do I create a separate js file? where do I put it? in wp-includes/js ?
how do i expose them to pages (do i put in functions.php, via the register and enque? how do I specify the path exactly? or is there another way to do this?
Is there a way not to expose to all pages, but rather to specific few ones?
In the using pages, how do I load and call these functions?
below is the structure of code I have now. Thanks! Yoav
<script> // an example for the functions i want to reuse function foo(x,y) { ... do stuff return z; } function goo() { // <![CDATA[ .. do stuff ... // ]]> } </script> <script> // an example for the real page val x = "something"; val y = "other"; var message = foo(x, y); // this will add some content to the page goo(); // this adds some more document.write(message); </script>