Question

Is there a built in function to load scripts only for particular template?

At them moment I am doing like so:

if (is_page('portfolio') || is_page('gallery')){

wp_register_script('jScrollpane', get_bloginfo('stylesheet_directory') . '/js/jquery.jscrollpane.min.js');
wp_enqueue_script('jScrollpane');
}

and it works as long as I call the pages "portfolio" and "gallery". I would like to have it more reusable, how can I achieve that?

Thank you in advance

Was it helpful?

Solution

You can use is_page_template('template.php') and just replace template.php with your template name.

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top