<script> tag). In that JS code, I want to write the contents of the JSON file to a variable. What is the proper approach to this?
- Can/should I enqueue the JSON file, just as I would a normal JS file (i.e.
wp_enqueue_scripts())? If so, how would I in-turn write the contents of the file to a JS variable? Would I do something like
myJson = json.parse('http://example.com/wp-contents/themes/your-theme/file.json')?
- Can I just use
includeto include the JSON file on the page? Actually now that I think about it, one can only use
includewith certain file extensions--correct?
- Should I perhaps use PHP to save the contents of the JSON file to a PHP variable, then pass that variable to the JS code?
Thanks in advance.