ThemeShaper Forums » Thematic

[closed]

Load a script for a particular template

(3 posts)
  • Started 12 years ago by mirko77
  • Latest reply from mirko77
  • This topic is resolved

Tags:

  1. 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

    Posted 12 years ago #
  2. http://codex.wordpress.org/Conditional_Tags

    sounds like you are looking for is_page_template. also note- that you cannot hook this function into 'init' if you are using is_page_template, b/c at 'init' (one of the first functions) it isn't aware of what the template is and so will never return true.

    you can hook the function into either template_redirect or maybe wp_print_scripts

    Posted 12 years ago #
  3. Thank you so much!
    I used template_redirect, thanks for that too ;)

    Posted 12 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.