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' ); ?>
Have commented out all of my javascript except for an alert, and the javascript works fine on non-WP webpage. So the problem is not there.
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.
Do I need to use the wp_enqueue_script to include javascript files in my theme, and if so, What am I doing wrong that causes the whole page to disappear on load?
First-time poster, thanks for your patience!