Bird
0
0

What will happen if you add this code to functions.php?

medium📝 component behavior Q5 of 15
Wordpress - Theme Structure and Basics
What will happen if you add this code to functions.php?
function load_custom_scripts() {
  wp_enqueue_script('custom-js', get_template_directory_uri() . '/js/custom.js');
}
add_action('wp_enqueue_scripts', 'load_custom_scripts');
AThe script will load only in the WordPress admin dashboard
BThe script will load but only on the homepage
CThe script will not load because wp_enqueue_script is invalid here
DThe custom.js script will be loaded on the front-end pages
Step-by-Step Solution
Solution:
  1. Step 1: Understand the hook 'wp_enqueue_scripts'

    This hook is used to enqueue scripts and styles on the front-end.
  2. Step 2: Analyze the function behavior

    The function enqueues 'custom.js' from the theme's js folder, so it loads on all front-end pages.
  3. Final Answer:

    The custom.js script will be loaded on the front-end pages -> Option D
  4. Quick Check:

    wp_enqueue_scripts hook loads scripts on front-end [OK]
Quick Trick: Use wp_enqueue_scripts to load front-end scripts [OK]
Common Mistakes:
  • Confusing front-end and admin script loading hooks
  • Thinking wp_enqueue_script can't be used in functions.php

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes