You should place the .js
file into your plugin directory (it can be root or any other folder like assets
or js
).
To enqueue JS and CSS files in the front-end:
function wp_357866_enqueue_frontend()
{
wp_enqueue_script('your-script', get_template_directory_uri() . '/path/to/js/your-script.js', array(), null, true); // You should set the last parameter to 'true' to load JS in the footer
wp_enqueue_style('your-style', get_stylesheet_directory_uri() . '/path/to/css/your-style.css', array(), null);
}
add_action( 'wp_enqueue_scripts', 'wp_357866_enqueue_frontend' );
Reference: wp_enqueue_scripts
To enqueue JS and CSS in the administration:
function wp_357866_enqueue_admin()
{
wp_enqueue_script('your-script', get_template_directory_uri() . '/path/to/js/your-script.js', array(), null, true); // You should set the last parameter to 'true' to load JS in the footer
wp_enqueue_style('your-style', get_stylesheet_directory_uri() . '/path/to/css/your-style.css', array(), null);
}
add_action( 'admin_enqueue_scripts', 'wp_357866_enqueue_admin' );
Reference: admin_enqueue_scripts