I’m using a handful of different element hooks to include differing JS code depending on the page the user is on.
However, within those different hooks I need to call commonly shared JS functions (e.g. a function for efficient cookie setting) and I’m looking for a solution so that I don’t have to include (and later potentially update) said functions over and over within every single hook. Instead I’d like to have said functions in a single spot and call this “global” spot from within the indiviual, page-specific hooks.
1. Create a Hook for all your Global scripts and set this to the Entire Site ( or wherever ).
2. Create a function in your child theme functions.php and call that function function from your page specific hooks.
The latter is the more logical way to do it as you can more easily pass variables to that function
Adding JS to my functions.php apparently was blocked by our clearfy plugin, so I went for your approach #1, i.e. creating a global hook and accessing its functions with “window.myFunctionName(myVar)”. This seems to work!