Ask any question about WordPress here... and get an instant response.
How can I enqueue scripts properly in a custom theme?
Asked on Nov 10, 2025
Answer
Enqueuing scripts in a custom WordPress theme is essential for properly loading JavaScript files without conflicts. This is done using the `wp_enqueue_script` function within the theme's `functions.php` file.
<!-- BEGIN COPY / PASTE -->
function my_theme_enqueue_scripts() {
wp_enqueue_script('custom-script', get_template_directory_uri() . '/js/custom-script.js', array('jquery'), null, true);
}
add_action('wp_enqueue_scripts', 'my_theme_enqueue_scripts');
<!-- END COPY / PASTE -->Additional Comment:
- Use `wp_enqueue_script` to add JavaScript files to your theme.
- Specify dependencies in the third parameter (e.g., `array('jquery')`).
- Set the last parameter to `true` to load the script in the footer.
- Always use `wp_enqueue_scripts` action to hook your function.
Recommended Links:
