Skip to content

Instantly share code, notes, and snippets.

@krogsgard
Created May 15, 2012 02:23
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krogsgard/2698599 to your computer and use it in GitHub Desktop.
Save krogsgard/2698599 to your computer and use it in GitHub Desktop.
Sample enqueue scripts action and function
<?php
/*
* WordPress Sample function and action
* for loading scripts in themes
*/
// Let's hook in our function with the javascript files with the wp_enqueue_scripts hook
add_action( 'wp_enqueue_scripts', 'wpcandy_load_javascript_files' );
// Register some javascript files, because we love javascript files. Enqueue a couple as well
function wpcandy_load_javascript_files() {
wp_register_script( 'info-caroufredsel', get_template_directory_uri() . '/js/jquery.carouFredSel-5.5.0-packed.js', array('jquery'), '5.5.0', true );
wp_register_script( 'info-carousel-instance', get_template_directory_uri() . '/js/info-carousel-instance.js', array('info-caroufredsel'), '1.0', true );
wp_register_script( 'jquery.flexslider', get_template_directory_uri().'/js/jquery.flexslider-min.js', array('jquery'), '1.7', true );
wp_register_script( 'home-page-main-flex-slider', get_template_directory_uri().'/js/home-page-main-flex-slider.js', array('jquery.flexslider'), '1.0', true );
wp_enqueue_script( 'info-carousel-instance' );
if ( is_front_page() ) {
wp_enqueue_script('home-page-main-flex-slider');
}
}
?>
@fjarrett
Copy link

Nice going, Krogsgard. And props for using get_template_directory_uri()! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment