0

How to enqueue script in WordPress ?

When I am using below code script enqueue properly.

wp_enqueue_script( 'adc-handlebars', get_template_directory_uri() . '/vendors/handlebars/handlebars.min.js', array(), '1.2.1', false );

But when I am using below code script is not enqueue.

wp_enqueue_script('adc-order-information', get_template_directory_uri().'/js/order_information.js', array(), '2.10.0', true);
2
  • 1
    Do you have any browser console errors?
    – Taruc
    Commented Jun 16, 2022 at 19:52
  • Thanks @Taruc. No, there is no error in browser console. Thanks.
    – Foysal
    Commented Jun 17, 2022 at 0:36

1 Answer 1

1

Your first snippet sets $in_footer to false so the the script will be added to the <head /> of your document.

The second snippet sets $in_footer to true and so it will be added at the bottom of your document (usually just before </body>, but it depends on where wp_footer() is called in your theme).

Read more about wp_enqueue_script()

6
  • Thanks @TheDeadMedic. But I couldn't find the script adc-order-information in Source code. I can find the first one. What will be the cause ? Thanks.
    – Foysal
    Commented Jun 16, 2022 at 14:13
  • 1
    @Foysal Are you calling both snippets in the same place? Is there a chance that adc-order-information is already registered elsewhere? Commented Jun 16, 2022 at 14:47
  • Thanks @TheDeadMedic. Yes, I am calling both snippets in the same place. I searched the whole code. There is no chance that adc-order-information is already registered elsewhere. Even I searched in Source code there is no adc-order-information.
    – Foysal
    Commented Jun 16, 2022 at 15:22
  • 1
    @Foysal What happens if you change the $in_footer argument from true to false? Commented Jun 16, 2022 at 15:30
  • 1
    @Foysal I'm sorry, I don't know what else to suggest Commented Jun 16, 2022 at 15:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.