#
September 7, 2012 at 6:12 pm
I like to do this by registering my scripts in my functions.php using wp_register_script(). Then when the element which requires that script asset is present use the wp_enqueue_script() function to make sure that it loads.
http://codex.wordpress.org/Function_Reference/wp_register_script
For example: in functions.php:
`wp_register_script( ‘jquery-bigtarget’, ‘http://url.to/jquery.bigtarget.1.0.1.js’, false, false, true );`
inside some IF statement:
`if ( $this ) wp_enqueue_script(‘jquery-bigtarget);`
I like to keep all my initializations in my main script.js file, so there is a nice way to put the init there but to render it useless when the necessary asset doesn’t load.
`if ( if ( $.isFunction($.fn.bigTarget) ) {
code goes here
}`