Enqueue script in the header section

In wordpress, wp_enqueue_script() allows plugins to queue scripts for the front end.

Syntax for enqueue is

wp_enqueue_script( string $handle, string $src = '', string[] $deps = array(), string|bool|null $ver = false, bool $in_footer = false )

Parameters are

Parameters

$handle string RequiredName of the script. Should be unique.$src string OptionalFull URL of the script, or path of the script relative to the WordPress root directory.

Default: ''$deps string[] OptionalAn array of registered script handles this script depends on.

Default: array()$ver string|bool|null OptionalString specifying script version number, if it has one, which is added to the URL as a query string for cache busting purposes. If version is set to false, a version number is automatically added equal to current installed WordPress version.
If set to null, no version is added.

Default: false$in_footer bool OptionalWhether to enqueue the script before </body> instead of in the <head>.
Default 'false'.If set to true,script will be enqueued in the footer.

So if the script have to be enqueued in header,make sure fifth parameter is false.

Leave a comment

Your email address will not be published. Required fields are marked *