0

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

  • 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 – Travis Northcutt Feb 3 '11 at 16:31
1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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