The goal- include my-script.js (dependant on jquery) in my WP theme.
The problem- When I use this code,(in the head element of the header template file) my entire page goes blank when loaded:
<?php wp_enqueue_script( 'jquery' ); ?> <?php wp_enqueue_script( 'my-script', "<?php echo get_template_directory_uri() . "/my-script.js"?>", array('jquery'), '1.0.0' ); ?>
I have tried putting the code in functions.php, wrapping the enqueue scripts in a function triggered by init, a la source 1 and other sources,
that approach failed to load the script at all.
More confusingly, according to the codex here, the usual approach of calling the script as I would in an HTML document is fine. And this approach, (skipping wp_enqueue_script), does load my-script.js just fine.
First-time poster, thanks for your patience!