WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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');

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

share|improve this question
Can you define "reusable" in context with what you mean? Explain how you would envision it working, and maybe we can help. – MikeSchinkel Feb 3 '11 at 11:57
Sorry if it was not clear...lucky for me Pippin gave the answer I needed. I want the final user to be free to call the pages whatever he wants and just select template "Portfolio" of "Gallery" based on his needs. Thank you anyway for your help. – Mirko Feb 3 '11 at 14:54
I suggest reading this excellent post on loading js in WordPress: scribu.net/wordpress/optimal-script-loading.html – tnorthcutt Feb 3 '11 at 16:31
up vote 1 down vote accepted

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.