Ask any question about WordPress here... and get an instant response.
How do I enqueue scripts and styles properly in a custom theme?
Asked on Nov 17, 2025
Answer
To enqueue scripts and styles properly in a custom WordPress theme, you should use the `wp_enqueue_scripts` action hook. This ensures that your theme's assets are loaded in the correct order and only when needed.
<!-- BEGIN COPY / PASTE -->
function my_theme_enqueue_scripts() {
// Enqueue a style
wp_enqueue_style('my-theme-style', get_stylesheet_uri());
// Enqueue a script with jQuery dependency
wp_enqueue_script('my-theme-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_stylesheet_uri()` for the main stylesheet of your theme.
- For additional styles or scripts, use `get_template_directory_uri()` to specify the path.
- Always specify dependencies and whether the script should load in the footer.
- Enqueuing ensures that WordPress can manage dependencies and avoid conflicts.
Recommended Links:
