HTML and CSS Reference
In-Depth Information
Registering JavaScript
Before registering your JavaScript, you'll need to decide on a few additional items:
the file's handle (i.e. the name by which WordPress will know the file);
other scripts that the file depends on (jQuery, for example);
the version number (optional);
where the file will appear in the HTML (the header or footer).
This chapter refers to building a theme, but the tips apply equally to building a plugin.
We'll use two JavaScript files to illustrate the power of the functions:
The first is base.js , which is a toolkit of functions used in our example website.
function makeRed ( selector ){
var $ = jQuery ; //enable $ alias within this scope
$ ( function (){
$ ( selector ). css ( 'color' , 'red' );
The base.js file relies on jQuery, so jQuery can be considered a dependency.
This is the first version of the file, version 1.0.0, and there is no reason to run this file in the
HTML header.
The second file, custom.js , is used to add the JavaScript goodness to our website.
makeRed ( '*' );
This custom.js file calls a function in base.js , so base.js is a dependency.
Like base.js , custom.js is version 1.0.0 and can be run in the HTML footer.
Search WWH ::

Custom Search