WordPress wp_enqueue_script only adds text to top of page source

You need to wrap your text with <?php and ?>.

Like this:

<?php

function my_scripts() {
    wp_enqueue_script( 'jquery' );

    wp_register_script( 'parallax', get_template_directory_uri() . '/parallax.js', array( 'jquery' ), NULL, true );
    wp_enqueue_script( 'parallax' );
}

add_action( 'wp_enqueue_scripts', 'my_scripts' );

?>

Otherwise, the PHP parser never sees it – and it’s sent as text to the browser.

I know some of this seems like hoops. It does at the start, believe me. But once you get how it works, and continue to learn more, it starts to make so much sense. I can tell you that from experience!

So, thank you for learning how to add scripts the WordPress way, rather than just adding <script> tags everywhere 🙂 You’ll thank yourself too if you use caching or minifying plugins later on, or need to fight with script dependencies.