Bird
0
0

What will happen if you run this code in your theme's functions.php?

medium📝 component behavior Q13 of 15
Wordpress - Theme Structure and Basics
What will happen if you run this code in your theme's functions.php?
function load_custom_scripts() {
  wp_enqueue_script('custom-js', get_template_directory_uri() . '/js/custom.js', array('jquery'), '1.0', true);
}
add_action('wp_enqueue_scripts', 'load_custom_scripts');
AThe custom.js script will be loaded in the footer after jQuery
BThe custom.js script will load in the header before jQuery
CThe script will not load because of a missing hook
DThe script will load but without jQuery dependency
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the enqueue parameters

    The function enqueues 'custom-js' with dependency on 'jquery', version '1.0', and last parameter true means load in footer.
  2. Step 2: Understand the hook and dependencies

    The function is hooked to 'wp_enqueue_scripts', so it runs properly. jQuery will load before custom.js because of the dependency.
  3. Final Answer:

    The custom.js script will be loaded in the footer after jQuery -> Option A
  4. Quick Check:

    Dependency + footer true = load after jQuery in footer [OK]
Quick Trick: Footer loading = last parameter true; dependencies load first [OK]
Common Mistakes:
  • Confusing footer true with header loading
  • Forgetting to hook function to wp_enqueue_scripts
  • Ignoring script dependencies

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes