No – you add the enqueue to your functions.php file and then hook it to an action such as template_redirect. See http://codex.wordpress.org/Function_Reference/wp_enqueue_script
Thanks for your patience esmi.. just to recap:
in my functions php file I add:
<?php
function my_init_method() {
wp_register_script( 'jquery', 'http://code.jquery.com/jquery-1.5.2.min.js');
wp_register_script( 'nivo', '<?php bloginfo('template_url'); ?>/scripts/slimbox2.js');
wp_register_script( 'slimbox', '<?php bloginfo('template_url'); ?>/scripts/slimbox2.js');
wp_register_script( 'picasa', '<?php bloginfo('template_url'); ?>/scripts/jquery.EmbedPicasaGallery.js');
wp_register_script( 'pwi', 'php bloginfo('template_url'); ?>/scripts/jquery.pwi-min.js');
wp_register_script( 'swf', '<?php bloginfo('template_url'); ?>/scripts/jquery.swfobject.1-1-1.min.js');
wp_register_script( 'simpletube', '<?php bloginfo('template_url'); ?>/scripts/jquery.simpletube.js');
wp_register_script( 'jqvalidate', '<?php bloginfo('template_url'); ?>/scripts/jquery.jqvalidate.js');
}
add_action('init', 'my_init_method');
?>
then in my header file I just call these scripts by using:
<?php wp_enqueue_script("jquery"); ?>
<?php wp_enqueue_script("nivo"); ?>
<?php wp_enqueue_script("slimbox"); ?>
<?php wp_enqueue_script("picasa"); ?>
<?php wp_enqueue_script("pwi"); ?>
<?php wp_enqueue_script("swf"); ?>
<?php wp_enqueue_script("simpletube"); ?>
<?php wp_enqueue_script("jqvalidate"); ?>
correct?
You call the scripts in the header file. Enqueuing them in functions.php adds them to the HEAD section of all pages. Example – adding a jQuery accordion script to all front facing pages:
// Add accordian menu
if ( !function_exists( 'emporium_init_accordian' ) ) :
function emporium_init_accordian() {
wp_enqueue_script('accordian',
get_template_directory_uri() . '/library/accordian-menu.js',
array('jquery'),
'3.0.2'
);
}
endif;
if( !is_admin() ) add_action('template_redirect', 'emporium_init_accordian');
So as long as I create a function for each script into my functions.php file then I should not have to call any scripts in my head, they will just automagically be there?
You don’t have to create a separate function for every script. You can enqueue multiple scripts within a single function if that works for you. The example above was kept separate for various reasons.
And, yes, all enqueued scripts will be available. The enqueue ensures that they are called in the HEAD section of a page.
Thanks again Esmi,
After reading up about this on some more blogs I feel like I am really close to getting it working, but all I am getting is a blank white screen at this point.
This is what I have inserted into the bottom of my functions file:
[Code moderated as per the Forum Rules. Please use the pastebin]
What am I doing wrong?
Nvm Esmi,
Thanks for your patience.
It was a syntax error.