Ask any question about WordPress here... and get an instant response.
Post this Question & Answer:
How can I enqueue scripts and styles properly in WordPress?
Asked on Jan 04, 2026
Answer
Enqueuing scripts and styles in WordPress is essential for properly loading assets in your theme or plugin. This ensures that files are loaded in the correct order and only when needed.
<!-- BEGIN COPY / PASTE -->
function my_theme_enqueue_scripts() {
wp_enqueue_style('my-style', get_template_directory_uri() . '/css/style.css');
wp_enqueue_script('my-script', get_template_directory_uri() . '/js/script.js', array('jquery'), null, true);
}
add_action('wp_enqueue_scripts', 'my_theme_enqueue_scripts');
<!-- END COPY / PASTE -->Additional Comment:
- Use "wp_enqueue_scripts" action hook to load scripts and styles in the front-end.
- For admin pages, use "admin_enqueue_scripts" instead.
- Always provide dependencies and specify whether the script should be loaded in the footer.
- Use version numbers to manage cache busting for your assets.
Recommended Links:
