How to enqueue custom js in wordpress?
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
To enqueue custom JavaScript in WordPress, you can use
wp_enqueue_script
function. Add your JavaScript file in child theme folder. Lets “custom-script.js” is your file, and it is located in “child-theme/js’ folder, then add the following code in functions.php to enqueue your script.custom-script
: The handle for the script, which is used as a unique identifier.get_stylesheet_directory_uri() . '/js/custom-script.js'
: The URL of the script file.array( 'jquery' )
: An array of dependencies. If the script not depends on jQuery, then you leave it as emptyarray( '' ).
1.0
: The version number of the script.true
: Whether to load the script in the footer (true
) or the header (false
).