Return to Snippet

Revision: 47767
at June 16, 2011 04:19 by jschultz76

Initial Code

function my_script_init() {
	if (!is_admin()) {
		// deregister local copy of jQuery
		// register google hosted jquery
		wp_register_script('jquery', '', false, '1.6.1');

		// register some other javascript file (just for the sake example)		
		wp_register_script('otherfile', get_bloginfo('stylesheet_directory').'/scripts/jquery.otherFile.js', array('jquery'));

		// register another file that requires that the other two files are loaded first		
		wp_register_script('mainjs', get_bloginfo('stylesheet_directory').'/scripts/main.js', array('jquery','otherfile'));
		wp_deregister_script( 'l10n' );
add_action('init', 'my_script_init');

Initial URL

Initial Description
This code should be added to the functions.php file in the theme's folder. The code will deregister the local copy of jQuery and instead include the google hosted copy. It will also register other scripts.

Initial Title
Include & Register Javascript files in WordPress in functions.php

Initial Tags
javascript, wordpress

Initial Language