HTML and CSS Reference
In-Depth Information
The custom.js file also indirectly relies on jQuery. But in this case, base.js could be edited to
be self-contained or to rely on another framework. There is no need for jQuery to be listed as a
dependency of custom.js .
It's now simply a matter of registering your JavaScript using the function
wp_register_script . This takes the following arguments:
$handle
A string
$source
A string
$dependancies
An array (optional)
$version
A string (optional)
$in_footer
True/false (optional, default is false)
When registering scripts, it is best to use the init hook and to register them all at once.
To register the scripts in our example, add the following to the theme's functions.php file:
function mytheme_register_scripts () {
//base.js - dependent on jQuery
wp_register_script (
'theme-base' , //handle
'/wp-content/themes/my-theme/base.js' , //source
array ( 'jquery' ), //dependencies
'1.0.0' , //version
true //run in footer
);
//custom.js - dependent on base.js
wp_register_script (
'theme-custom' ,
Search WWH ::




Custom Search