Bird
0
0

You want to enqueue a script that depends on jQuery and load it in the footer. Which is the correct way to do this?

hard📝 Application Q8 of 15
Wordpress - Theme Structure and Basics
You want to enqueue a script that depends on jQuery and load it in the footer. Which is the correct way to do this?
Awp_enqueue_script('custom-js', get_template_directory_uri() . '/js/custom.js', array('jquery'), null, false);
Bwp_enqueue_script('custom-js', get_template_directory_uri() . '/js/custom.js', array('jquery'), null, true);
Cwp_enqueue_script('custom-js', get_template_directory_uri() . '/js/custom.js', array(), null, false);
Dwp_enqueue_script('custom-js', get_template_directory_uri() . '/js/custom.js', array(), null, true);
Step-by-Step Solution
Solution:
  1. Step 1: Set jQuery as a dependency

    Pass array('jquery') as the third argument to ensure jQuery loads first.
  2. Step 2: Load script in footer

    Set the last argument to true to load the script before the closing body tag.
  3. Final Answer:

    wp_enqueue_script('custom-js', get_template_directory_uri() . '/js/custom.js', array('jquery'), null, true); -> Option B
  4. Quick Check:

    Dependency and footer loading = wp_enqueue_script('custom-js', get_template_directory_uri() . '/js/custom.js', array('jquery'), null, true); [OK]
Quick Trick: Use array('jquery') and true for footer loading [OK]
Common Mistakes:
  • Not specifying dependencies
  • Loading scripts in header unintentionally
  • Passing wrong arguments order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes