How to load javascript on custom page template?

You can use is_page_template to check if you template is being used and load your scripts based on that ex:

Add this code to your functions.php:

add_action('wp_enqueue_scripts','Load_Template_Scripts_wpa83855');
function Load_Template_Scripts_wpa83855(){
    if ( is_page_template('custom-page.php') ) {
        wp_enqueue_script('my-script', 'path/to/script.js');
    } 
}

Leave a Comment