-
Notifications
You must be signed in to change notification settings - Fork 5
admin enqueue script
Alberto Parziale edited this page Aug 30, 2019
·
1 revision
Aeria makes enqueuing js scripts easy. To do so, you just have to create a new ScriptsEnqueuer
, which constructor accepts:
-
name
(required) is the script's name. It should be unique. -
path
(required) is the script's path, either full or relative to the WP root directory. -
deps
is an array of registered script handles this script depends on. -
ver
is a string defining the script's version. If it has one, it gets added to the URL for cache busting purposes. -
in_footer
is a boolean stating if the script has to be enqueued in the<head>
, or before the</body>
tag.
After declaring the ScriptsEnqueuer
, you just need to register it into an AdminEnqueueScriptsAction
and dispatch it.
$js_script = new Aeria\Action\Enqueuers\ScriptsEnqueuer(
'book-js',
__DIR__.'/scripts/script.js',
null,
null,
true
);
$admin_enqueue_scripts = new Aeria\Action\Actions\AdminEnqueueScripts();
$admin_enqueue_scripts->register($js_script);
$admin_enqueue_scripts->dispatch(aeria());