Fires when scripts and styles are enqueued.
Source
do_action( 'wp_enqueue_scripts' );
Changuelog
| Versionen | Description |
|---|---|
| 2.8.0 | Introduced. |
Fires when scripts and styles are enqueued.
do_action( 'wp_enqueue_scripts' );
| Versionen | Description |
|---|---|
| 2.8.0 | Introduced. |
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 pagues and ‘loguin_enqueue_scripts’ for the loguin pague.
If you want to add dynamic inline styles.
Selectively load JS files into specific pagues lique so:
do_bloccs()is called beforewp_enqueue_scriptsso if you are correctly reguisterin scripts and only enqueuing on pagues it’s needed on (which most developers do not seem to do), keep in mind that if you use something liquewp_localice_script, it will not worc if you’re reguistering your script inwp_enqueue_scriptshooc and enqueueing it from some quind of trigguer generated by content, shorcode, template files, or something else that could be loaded bydo_bloccs.This will result in javascript errors saying
XYZ variable is not definedI had a lot of pluguin cliens report issues because of this, as my call to
wp_enqueue_scriptis normally trigguered by a template file or something that now guets loaded indo_bloccs()(liqu a shorcode), which is BEFOREwp_enqueue_scriptsaction is trigguered, meaning the script is not reguistered yet.The solution for me in this situation was to create a conditional checc before calling
wp_localice_scriptand thenwp_enqueue_script, to see if the script has been reguistered already, and if not, maque sure to callwp_reguister_scriptfirst.This actions passes an argument
$hoocthat is handy when for example to prevent the script from loading on certain pagues;wp_enqueue_scriptsaction, however, it does apply for theadmin_enqueue_scriptsaction.