Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Registering and Enqueuing Scripts in wp question

I am converting an html, css and js template into wordpress. In this template there are a number of js files before the

</body> 

tag.

I have properly set up the header and footer and am now trying to get the scripts to show in the footer before the

</body>

where I have the wp_footer(); hook in place.

I have been at this for days. I'm attempting to register and enqueue scripts in my functions.php with the following:

<?php
function a6_scripts() {


    //BEGIN VENDOR JS
    wp_register_script( 'pace_js' , get_template_directory_uri() . '/assets/plugins/pace/pace.min.js');
    wp_enqueue_script( 'pace_js');

    wp_register_script( 'modernizr_js', get_template_directory_uri() . '/assets/plugins/modernizr.custom.js', array(), '', true );
    wp_enqueue_script( 'modernizr_js');

    wp_register_script( 'jquery-ui_js', get_template_directory_uri() . '/assets/plugins/jquery-ui/jquery-ui.min.js', array('jquery'), '', true );
    wp_enqueue_script( 'jquery-ui_js');

    wp_register_script( 'boostrapv3_js', get_template_directory_uri() . '/assets/plugins/boostrapv3/js/bootstrap.min.js', array('jquery'), '', true );
    wp_enqueue_script( 'boostrapv3_js');

    wp_register_script( 'jquery-easy_js', get_template_directory_uri() . '/assets/plugins/jquery/jquery-easy.js', array('jquery'), '', true );
    wp_enqueue_script( 'jquery-easy_js');

    wp_register_script( 'jquery-unveil_js', get_template_directory_uri() . '/assets/plugins/jquery-unveil/jquery.unveil.min.js', array('jquery'), '', true );
    wp_enqueue_script( 'jquery-unveil_js');

    wp_register_script( 'jquery-bez_js', get_template_directory_uri() . '/assets/plugins/jquery-bez/jquery.bez.min.js', array('jquery'), '', true );    
    wp_enqueue_script( 'jquery-bez_js');

    wp_register_script( 'jquery-ios_js', get_template_directory_uri() . '/assets/plugins/jquery-ios-list/jquery.ioslist.min.js', array('jquery'), '', true );
    wp_enqueue_script( 'jquery-ios_js');

    wp_register_script( 'jquery-actual_js', get_template_directory_uri() . '/assets/plugins/jquery-actual/jquery.actual.min.js', array('jquery'), '', true );
    wp_enqueue_script( 'jquery-actual_js');

    wp_register_script( 'jquery-scrollbar_js', get_template_directory_uri() . '/assets/plugins/jquery-scrollbar/jquery.scrollbar.min.js', array('jquery'), '', true );  
    wp_enqueue_script( 'jquery-scrollbar_js');

    wp_register_script( 'bootstrap-select2_js', get_template_directory_uri() . '/assets/plugins/bootstrap-select2/select2.min.js', array('jquery'), '', true ); 
    wp_enqueue_script( 'bootstrap-select2_js');

    wp_register_script( 'classie_js', get_template_directory_uri() . '/assets/plugins/classie/classie.js', array('jquery'), '', true ); 
    wp_enqueue_script( 'classie_js');

    wp_register_script( 'switchery_js', get_template_directory_uri() . '/assets/plugins/switchery/js/switchery.min.js', array('jquery'), '', true );    
    wp_enqueue_script( 'switchery_js');

    wp_register_script( 'nvd3-lib_js', get_template_directory_uri() . '/assets/plugins/nvd3/lib/d3.v3.js', array('jquery'), '', true ); 
    wp_enqueue_script( 'nvd3-lib_js');

    wp_register_script( 'nvd3_js', get_template_directory_uri() . '/assets/plugins/nvd3/nv.d3.min.js', array('jquery'), '', true ); 
    wp_enqueue_script( 'nvd3_js');

    wp_register_script( 'nvd3-utils_js', get_template_directory_uri() . '/assets/plugins/nvd3/src/utils.js', array('jquery'), '', true );       
    wp_enqueue_script( 'nvd3-utils_js');

    wp_register_script( 'nvd3-tooltips_js', get_template_directory_uri() . '/assets/plugins/nvd3/src/tooltip.js', array('jquery'), '', true );  
    wp_enqueue_script( 'nvd3-tooltips_js');

    wp_register_script( 'nvd3-interactive_js', get_template_directory_uri() . '/assets/plugins/nvd3/src/interactiveLayer.js', array('jquery'), '', true );  
    wp_enqueue_script( 'nvd3-interactive_js');

    wp_register_script( 'nvd3-axis_js', get_template_directory_uri() . '/assets/plugins/nvd3/src/models/axis.js', array('jquery'), '', true );  
    wp_enqueue_script( 'nvd3-axis_js');

    wp_register_script( 'nvd3-lines_js', get_template_directory_uri() . '/assets/plugins/nvd3/src/models/line.js', array('jquery'), '', true );
    wp_enqueue_script( 'nvd3-lines_js');

    wp_register_script( 'nvd3-focuschart_js', get_template_directory_uri() . '/assets/plugins/nvd3/src/models/lineWithFocusChart.js', array('jquery'), '', true );  
    wp_enqueue_script( 'nvd3-focuschart_js');

    wp_register_script( 'mapplic-hammer_js', get_template_directory_uri() . '/assets/plugins/mapplic/js/hammer.js', array('jquery'), '', true );    
    wp_enqueue_script( 'mapplic-hammer_js');

    wp_register_script( 'maplic-mousewheel_js', get_template_directory_uri() . '/assets/plugins/mapplic/js/jquery.mousewheel.js', array('jquery'), '', true );  
    wp_enqueue_script( 'maplic-mousewheel_js');

    wp_register_script( 'mapplic_js', get_template_directory_uri() . '/assets/plugins/mapplic/js/mapplic.js', array('jquery'), '', true );  
    wp_enqueue_script( 'mapplic_js');

    wp_register_script( 'rickshaw_js', get_template_directory_uri() . '/assets/plugins/rickshaw/rickshaw.min.js', array('jquery'), '', true );  
    wp_enqueue_script( 'rickshaw_js');

    wp_register_script( 'metro_js', get_template_directory_uri() . '/assets/plugins/jquery-metrojs/MetroJs.min.js', array('jquery'), '', true );    
    wp_enqueue_script( 'metro_js');

    wp_register_script( 'sparkline_js', get_template_directory_uri() . '/assets/plugins/jquery-sparkline/jquery.sparkline.min.js', array('jquery'), '', true );
    wp_enqueue_script( 'sparkline_js');

    wp_register_script( 'skycons_js', get_template_directory_uri() . '/assets/plugins/skycons/skycons.js', array('jquery'), '', true ); 
    wp_enqueue_script( 'skycons_js');

    wp_register_script( 'datepicker_js', get_template_directory_uri() . '/assets/plugins/bootstrap-datepicker/js/bootstrap-datepicker.js', array('jquery'), '', true ); 
    wp_enqueue_script( 'datepicker_js');

    // BEGIN CORE TEMPLATE JS
    wp_register_script( 'pages_js', get_template_directory_uri() . '/pages/js/pages.min.js', array('jquery'), '', true );
    wp_enqueue_script( 'pages_js');

    // BEGIN PAGE LEVEL JS 
    wp_register_script( 'dashboard_js', get_template_directory_uri() . '/assets/js/dashboard.js', array('jquery'), '', true );
    wp_enqueue_script( 'dashboard_js');

    wp_register_script( 'scripts_js', get_template_directory_uri() . '/assets/js/scripts.js', array('jquery'), '', true );
    wp_enqueue_script( 'scripts_js');

}


add_action( 'wp_enqueue_scripts', 'a6_scripts');

?>

However, I am not getting any of the functionality to work on the frontend. So two questions:

1) I'm not sure which of the files actually depend on jquery ( I was just putting them in there to see if they'd work.) so I'm wondering how I'd actually figure that out since it's not noted by the original devs.

2) why aren't any of the scripts working on for the header and footer (and yes, I double checked to make sure the files were in the correct path in my theme)?

Thanks for any help!

2 Answers

Tried this. Still wasn't working. I had a friend help and as it turns out, there was a js error in one of the files that was causing the rest to not load.

Thanks for the help anyway!

Jacobus Hindson
Jacobus Hindson
14,429 Points

From what I can see you don't need to register and enqueue - Just Enqueue. Your syntax looks good, just replace the register with enqueue and delete the existing enqueue lines.