Ask any question about WordPress here... and get an instant response.
How can I enqueue custom scripts and styles properly in my theme?
Asked on Nov 28, 2025
Answer
To properly enqueue custom scripts and styles in your WordPress theme, you should use the `wp_enqueue_scripts` action hook. This ensures that your assets are loaded correctly and in the right order.
<!-- BEGIN COPY / PASTE -->
function my_theme_enqueue_scripts() {
// Enqueue a custom style
wp_enqueue_style('my-custom-style', get_template_directory_uri() . '/css/custom-style.css');
// Enqueue a custom script
wp_enqueue_script('my-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:
- Always use `get_template_directory_uri()` for child themes, or `get_stylesheet_directory_uri()` if you're working with a child theme.
- Use dependencies (e.g., `array('jquery')`) to ensure scripts load in the correct order.
- Set the last parameter of `wp_enqueue_script()` to `true` to load scripts in the footer.
Recommended Links:
