-
Notifications
You must be signed in to change notification settings - Fork 5
Enqueue Functions
Renato Alves edited this page Aug 10, 2026
·
6 revisions
The am_enqueue_* functions will enqueue an asset with additional attributes based upon its load_method value. Options can be passed in as an array or individual parameters.
// Enqueue a JavaScript asset.
am_enqueue_script(
[
'handle' => 'footer-script',
'src' => 'js/script.js',
'deps' => [],
'condition' => 'global',
'load_method' => 'sync', // 'sync', 'inline', 'async', 'defer'
'version' => '1.0.0',
'load_hook' => 'wp_footer',
]
);Use am_modify_load_method to modify the load method of an already-enqueued script.
// Defer an enqueued JavaScript asset.
am_modify_load_method(
[
'handle' => 'footer-script',
'load_method' => 'defer',
]
);// Load a CSS asset asynchronously.
am_enqueue_style(
[
'handle' => 'site-styles',
'src' => 'css/styles.css',
'deps' => [],
'condition' => 'global',
'load_method' => 'async', // 'sync', 'inline', 'async', 'defer'
'version' => '1.0.0',
'load_hook' => 'wp_head',
'media' => 'all', // 'print', 'screen', or any valid media query
]
);The am_enqueue_* functions use the same parameters as their core WordPress enqueue equivelant, with the exception of the $in_footer parameter for scripts; use 'load_hook' (details below) instead.
Additional options:
| Name | Description | Default |
|---|---|---|
condition |
The condition for which this asset should load | 'global' |
load_hook |
'wp_head' |
|
— wp_head
|
Load this asset via wp_head
|
|
— wp_footer
|
Load this asset via wp_footer
|
|
load_method |
'sync' |
|
— sync
|
Use the corewp_enqueue function |
|
— async
|
Adds the async attribute to the enqueue |
|
— defer
|
Adds the defer attribute to the enqueue |
|
— inline
|
Prints the asset inline in the document head |