-
Notifications
You must be signed in to change notification settings - Fork 5
Inline Assets
Renato Alves edited this page Aug 10, 2026
·
1 revision
Use load_method => inline with an absolute src path for either enqueue function to print the contents of the file to the document head.
Print the contents of a file
// Print the contents of this CSS asset into a <style> tag.
// Also works with `am_enqueue_script` for printing a JavaScript asset into a <script> tag.
am_enqueue_style(
[
'handle' => 'inline-styles',
'src' => 'css/styles.css',
'condition' => 'global',
'load_method' => 'inline',
]
);Print inline global variables
Pass an array of values as the src to print global JavaScript variables to the document head.
// Add JavaScript values to a property on the `window.amScripts` object.
am_enqueue_script(
[
'handle' => 'inline-vars',
'src' => [
'myGlobalVar' => true,
],
'load_method' => 'inline',
]
);The result will be an object added to the window.amScripts[$handle] object:
<script class="wp-asset-manager inline-vars" type="text/javascript">window.amScripts = window.amScripts || {}; window.amScripts["inline-vars"] = {"myGlobalVar":true}</script>Use the am_inline_script_context filter to change the global object name.
add_filter(
'am_inline_script_context',
function() {
return 'myContext'; // window.myContext[$handle]
}
);