Ask any question about WordPress here... and get an instant response.
How can I enqueue custom scripts and styles in a WordPress theme?
Asked on Nov 14, 2025
Answer
To enqueue custom scripts and styles in a WordPress theme, you should use the `wp_enqueue_scripts` action hook. This allows you to properly add your scripts and styles to the WordPress front-end in a way that ensures compatibility and avoids conflicts.
<!-- BEGIN COPY / PASTE -->
function my_custom_scripts() {
// Enqueue a custom stylesheet
wp_enqueue_style('my-custom-style', get_template_directory_uri() . '/css/custom-style.css');
// Enqueue a custom script with jQuery as a dependency
wp_enqueue_script('my-custom-script', get_template_directory_uri() . '/js/custom-script.js', array('jquery'), null, true);
}
add_action('wp_enqueue_scripts', 'my_custom_scripts');
<!-- END COPY / PASTE -->Additional Comment:
- Place this code in your theme's `functions.php` file.
- Ensure that the paths to your CSS and JS files are correct relative to your theme directory.
- Using `wp_enqueue_script` and `wp_enqueue_style` ensures that dependencies are managed and scripts are loaded in the correct order.
- Setting the last parameter of `wp_enqueue_script` to `true` loads the script in the footer, which is generally recommended for performance.
Recommended Links:
