Add Javascript code to a template page in WordPress

I would like to use this Grid Column Carousel. I have added some code in functions.php because I would like this carousel to be only on some pages. So it requires to include a js file which load on my homepage, but also this piece of code :

<!-- Include the script--<
<script src="js/GridColumnCarousel.js"></script>

<!-- initialize the carousel -->
  window.onload = function() {
    var options = {
      elem: document.getElementsByClassName('example-1')[0],
      gridColClasses: 'col-xs-12 col-sm-6 col-md-4 col-lg-3'

    var gCCarousel = new GCCarousel(options);      

How do I add it only on my page-custom.php ?

My code in functions

    function load_js_slider(){
        if ( is_page_template('accueil_page.php') ) {
            wp_enqueue_script('slider_script', get_template_directory_uri() . '/js/GridColumnCarousel.js');
            wp_enqueue_script('slider_script', get_template_directory_uri() . '/js/slider.js');

Thank you

Read more here: Add Javascript code to a template page in WordPress

Leave a Reply

Your email address will not be published. Required fields are marked *