1. Open up the 'header.php' file for your theme in a code editor. This file is found in the following location:/your-site/wp-content/themes/theme-name/Look for the ending
tag and check that the code
appears above any
tags but below all other tags between
and
. If it is not there, add that line.
2. Add your
tags to include the JavaScripts you wish to use. When the JavaScript is in an external .JS file, include it like this:
/yourscript.js'>
The above code uses
to tell WordPress to look inside your theme folder for the JavaScript. Many developers put all scripts into a folder called 'js' or 'src' to keep things organized. In such a case, remember to include that folder in the path to your script. All JavaScript that is directly on the page goes between
and
tags.
3. When using a JavaSript that depends on a library such as jQuery, MooTools or YUI, you must first enqueue that library. Static HTML websites need you to include libraries as scripts, but WordPress already contains them. Here is an example of how to enqueue jQuery:
Place the enqueue code above
to make it work properly. After enqueing, you can then include JavaScripts that use that library the same way you would include other JavaScripts in WordPress.