do_action( 'wp_enqueue_scripts' )
Fires when scripts and styles are enqueued.
More Information
wp_enqueue_scripts
is the proper hook to use when enqueuing scripts and styles that are meant to appear on the front end. Despite the name, it is used for enqueuing both scripts and styles.
Usage
function themeslug_enqueue_style() {
wp_enqueue_style( 'my-theme', 'style.css', false );
}
function themeslug_enqueue_script() {
wp_enqueue_script( 'my-js', 'filename.js', false );
}
add_action( 'wp_enqueue_scripts', 'themeslug_enqueue_style' );
add_action( 'wp_enqueue_scripts', 'themeslug_enqueue_script' );
Source
File: wp-includes/script-loader.php
.
View all references
do_action( 'wp_enqueue_scripts' );
Changelog
Version | Description |
---|---|
2.8.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.
Basic Example
Instead of this Action, use ‘admin_enqueue_scripts’ for Admin pages and ‘login_enqueue_scripts’ for the login page.
If you want to add dynamic inline styles.
Selectively load JS files into specific pages like so:
This actions passes an argument
$hook
that is handy when for example to prevent the script from loading on certain pages;Top ↑
Feedback
This is not true for the
wp_enqueue_scripts
action, however, it does apply for theadmin_enqueue_scripts
action. — By thelevicole —That is not true. You are thinking of the admin part. Check https://developer.wordpress.org/reference/functions/wp_enqueue_scripts/, and https://developer.wordpress.org/reference/hooks/admin_enqueue_scripts/ As you can see only the admin_ part has the $hook_suffix. — By Beda —