Ask any question about WordPress here... and get an instant response.
Post this Question & Answer:
How can I enqueue scripts and styles properly in a custom WordPress theme?
Asked on Jan 28, 2026
Answer
Enqueuing scripts and styles in a custom WordPress theme ensures that they are loaded correctly and efficiently. This is done using WordPress functions within the theme's functions.php file.
<!-- 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 as a dependency
wp_enqueue_script('my-theme-script', get_template_directory_uri() . '/js/custom.js', array('jquery'), null, true);
}
add_action('wp_enqueue_scripts', 'my_theme_enqueue_scripts');
<!-- END COPY / PASTE -->Additional Comment:
- Use "wp_enqueue_style" and "wp_enqueue_script" to add styles and scripts.
- Ensure dependencies are listed in the array parameter to avoid conflicts.
- Set the last parameter of "wp_enqueue_script" to true to load scripts in the footer.
- Place this code in your theme's functions.php file.
Recommended Links:
