Site icon Hip-Hop Website Design and Development

How to add JS snippet before closing <head> tag?

I’m setting up jQuery UI on one of my WordPress pages that uses a custom template (course-landing-page.php). I enqueued the scripts for jQuery UI the proper way, but I need to add a JavaScript snippet AFTER the scripts in order to register the tabs on the page.

This is what the code in my functions.php file looks like:

    wp_enqueue_script( 'jquery2', '//code.jquery.com/jquery-1.10.2.js', array( 'jquery' ), '1.10.2', false );

wp_enqueue_script( 'jqueryui', '//code.jquery.com/ui/1.11.4/jquery-ui.js', array( 'jquery' ), '1.11.4', false );


// Add the jQuery 'tabs' code to pages that use the 'course-landing-page.php' template

add_action('wp_enqueue_scripts','jQuery_UI_Tabs');
function jQuery_UI_Tabs(){
    if ( is_page_template('course-landing-page.php') ) {
        echo '<script>
                $(function() {
                    $( "#tabs" ).tabs();
                });
            </script>';

    }

It works great, EXCEPT for the fact that the JavaScript snippet is displaying BEFORE the enqueued jQuery UI scripts, and therefore it’s causing the tabs not to work properly. How can I make it so the snippet shows up AFTER the enqueued scripts in the header?