Action Hook since 2.1.0
wp_enqueue_scripts
The correct hook to enqueue frontend assets
Description
Queue front-end CSS and JS here. WordPress prints the tags during wp_head / wp_footer — do not echo link or script tags yourself.
When it runs
Front-end only. Runs as a callback attached to wp_head at priority 1, before other wp_head callbacks print markup.
Signature
do_action( 'wp_enqueue_scripts' );Examples
Basic
add_action( 'wp_enqueue_scripts', function() {
wp_enqueue_style( 'my-style', get_stylesheet_uri() );
wp_enqueue_script( 'my-script', get_template_directory_uri() . '/js/main.js', [], '1.0', true );
} );Register the theme stylesheet and a footer script the core way.
Real case
add_action( 'wp_enqueue_scripts', function() {
if ( is_singular( 'book' ) ) {
wp_enqueue_style( 'book-single', get_template_directory_uri() . '/css/book-single.css' );
}
} );Load a stylesheet only on single book pages.
Common Use Cases
- Enqueue theme stylesheet
- Load JavaScript libraries
- Conditionally load assets per page
- Pass PHP data to JS via wp_localize_script
- Migrate off bundled jQuery (deprecated direction in core) toward vanilla JS or a bundler
Common mistakes
- Echoing <script> tags in wp_head instead of wp_enqueue_script()
Related hooks
FAQ
Why did my script load but not run in the right order?
Set proper dependency arrays (e.g. ['jquery']) in wp_enqueue_script() instead of relying on hook priority to control load order.
Is wp_enqueue_scripts the right hook for loading scripts inside the block editor?
No — that's enqueue_block_editor_assets (editor only) or enqueue_block_assets (editor + front-end). wp_enqueue_scripts only runs for the public front-end.
Source: wp-includes/script-loader.php