How to wordpress add javascript to page template

How to wordpress add javascript to page template

For many purpose and designs we use the page template in wordpress site. WordPress tutorial for, How to wordpress add javascript to page template. Some time we need to load the custom javascript to page template. Here is code for same.

How to wordpress add javascript to page template

For that we can use following code.

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

For loading any script or any custom code you can use above action in wordpress. Above code you need to add in functions.php file. Which you can find in your wordpress theme folder.

How to wordpress add javascript to page template
How to wordpress add javascript to page template

Published by

Purab

I am Purab from India, Software development is my profession and teaching is my passion. Programmers blog dedicated to the JAVA, Python, PHP, DevOps and Opensource Frameworks. Purab's Github Repo Youtube Chanel Video Tutorials Connect to on LinkedIn

One thought on “How to wordpress add javascript to page template”

Leave a Reply

Your email address will not be published.