wppaste
WordPress

do_action( 'wp_enqueue_scripts' )

Since
2.8.0

Action wp_enqueue_scripts is where front-end CSS and JavaScript are loaded, via wp_enqueue_style() and wp_enqueue_script() in a hooked callback. It fires only on the front end; use admin_enqueue_scripts for dashboard pages and enqueue_block_editor_assets for editor assets.

Fires when scripts and styles are enqueued.

Compatibility

WordPress
since 2.8.0
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0).

Code examples

Every example is editable and runs in a real WordPress booted in your browser by WordPress Playground. Press Run, then edit the code: clicking away re-runs it. Nothing is sent anywhere until you do.

Enqueue a theme stylesheet and script

Register all front-end assets from one callback so WordPress can resolve dependencies and print the tags in the right place.

add_action( 'wp_enqueue_scripts', 'mytheme_enqueue_assets' );

function mytheme_enqueue_assets() {
	$version = wp_get_theme()->get( 'Version' );

	wp_enqueue_style( 'mytheme-style', get_stylesheet_uri(), array(), $version );

	wp_enqueue_script(
		'mytheme-nav',
		get_template_directory_uri() . '/js/nav.js',
		array(),
		$version,
		array( 'in_footer' => true )
	);
}

Despite the name, stylesheets are enqueued here too. Echoing script or link tags directly into wp_head skips the dependency system and is the usual cause of assets loading twice or in the wrong order.

Where this hook fires · 1

  • wp-includes/script-loader.php:2329wp_enqueue_scripts()

Source code

function wp_enqueue_scripts() {	/**	 * Fires when scripts and styles are enqueued.	 *	 * @since 2.8.0	 */	do_action( 'wp_enqueue_scripts' );} /** * Prints the styles queue in the HTML head on admin pages. * * @since 2.8.0

Changelog

Introduced in 2.8.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.0.4 tag, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.