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 19, 2025
Answer
To enqueue custom scripts and styles in a WordPress theme, you should use the `wp_enqueue_scripts` action hook. This ensures that your scripts and styles are loaded properly and in the correct order.
<!-- BEGIN COPY / PASTE -->
function my_theme_enqueue_scripts() {
// Enqueue a custom style
wp_enqueue_style('custom-style', get_template_directory_uri() . '/css/custom-style.css');
// Enqueue a custom script
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 `get_template_directory_uri()` for parent themes and `get_stylesheet_directory_uri()` for child themes.
- The `wp_enqueue_script` function's parameters include dependencies (e.g., `array('jquery')`), version, and whether to load in the footer (true/false).
- Always use the `wp_enqueue_scripts` action hook to ensure proper loading.
Recommended Links:
