Created
January 10, 2022 21:27
-
-
Save JPry/2d5db5cc7995eb9724f706037cd4bfdf to your computer and use it in GitHub Desktop.
An example for including a JavaScript file into WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Example including a JS file into WordPress. | |
*/ | |
add_action( 'wp_enqueue_scripts', 'jpry_example_include_scripts' ); | |
function jpry_example_include_scripts() { | |
wp_enqueue_script( | |
'jpry-example-script', // This is an arbitrary name to reference this particular script | |
'https://example.com/wp-content/plugins/jpry-example/example.js', // This is the URL. For example purposes I've put the whole URL, but in WordPress, you'd usually have some other method for generating the URL for you | |
array(), // An array of other script names, if any, that this script depends on. These will be loaded prior to this script | |
'1.0.0', // This is a version string for browser caching purposes | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
console.log('Successfully loaded the example.js file!'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment