@raphael_tillman
To include JavaScript in your WordPress plugin, you can follow these steps:
1 2 3 4 |
function myplugin_enqueue_script() { wp_enqueue_script( 'myplugin-custom-script', plugins_url( '/js/my-script.js', __FILE__ ), array( 'jquery' ), '1.0.0', true ); } add_action( 'wp_enqueue_scripts', 'myplugin_enqueue_script' ); |
Here, my-plugin-name-custom-script
is the handle for your script, plugins_url()
is used to get the URL of the plugin directory, /js/my-script.js
is the path to your JavaScript file relative to the plugin directory, and array( 'jquery' )
specifies that your script depends on jQuery.
Remember to replace myplugin
and file paths with your actual plugin name and file paths.
By following these steps, you can easily include JavaScript in your WordPress plugin.