Ask any question about WordPress here... and get an instant response.
How do I enqueue scripts and styles properly in a WordPress theme?
Asked on Nov 26, 2025
Answer
Enqueuing scripts and styles in a WordPress theme is essential for properly loading assets in the right order and avoiding conflicts. This is typically done using the `wp_enqueue_scripts` action hook in your theme's `functions.php` file.
<!-- BEGIN COPY / PASTE -->
function my_theme_enqueue_scripts() {
// Enqueue a stylesheet
wp_enqueue_style('my-theme-style', get_stylesheet_uri());
// Enqueue a script with jQuery as a 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()` to enqueue the main stylesheet of your theme.
- For scripts, specify dependencies in the third parameter (e.g., `array('jquery')`).
- Set the last parameter of `wp_enqueue_script` to `true` to load the script in the footer.
- Always use `wp_enqueue_scripts` action to ensure proper loading order and avoid conflicts.
Recommended Links:
