Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question
1  
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
add comment

1 Answer 1

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
add comment

Your Answer

 
discard

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.