How do I enqueue a custom script in the WordPress admin area?
Asked on Oct 25, 2025
Answer
To enqueue a custom script in the WordPress admin area, you need to use the `admin_enqueue_scripts` action hook. This allows you to add your script to the admin pages efficiently.
<!-- BEGIN COPY / PASTE -->
function my_custom_admin_script() {
wp_enqueue_script('my-custom-script', plugin_dir_url(__FILE__) . 'js/my-custom-script.js', array('jquery'), '1.0', true);
}
add_action('admin_enqueue_scripts', 'my_custom_admin_script');
<!-- END COPY / PASTE -->Additional Comment:
- Ensure your script path is correct and the file exists in the specified location.
- Use dependencies like 'jquery' if your script requires them.
- Set the last parameter to true to load the script in the footer for better performance.
Recommended Links: