-
Notifications
You must be signed in to change notification settings - Fork 1
Loading JavaScript
Brian McCoy edited this page Feb 23, 2018
·
4 revisions
- Store your JavaScript files under
assets/jsin your theme.
- Inside your theme open
/app/assets/js-assets.php - Add a load_js() call. The first parameter is the URL to the JS file. The second optional parameter is an array of arguments. See arguments.
- If
handleis not defined as an arg the URL parameter will be used. - If
veris not defined as an arg the theme version will be used.
If you don't define "ver" then it will append the theme version to your CSS file's URL. You can use this for cache busting - simply bump the version number of your theme.
If you simply need to load a JavaScript file you can do:
load_js( _templateURL . '/assets/js/application.js' );Here's an example for loading jQuery from the Google CDN:
wp_deregister_script( 'jquery' );
load_js( '//ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array(
'handle' => 'jquery'
) );