Saturday, June 21, 2014
How to Use JavaScript With WordPress
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 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 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.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment