Bird
0
0

Identify the error in this code snippet:

medium📝 Debug Q6 of 15
Wordpress - Theme Structure and Basics
Identify the error in this code snippet:
function add_scripts() {
  wp_enqueue_script('custom-js', get_template_directory_uri() . '/js/custom.js');
}
add_action('init', 'add_scripts');
AMissing the script handle
BNo error, code is correct
CIncorrect file path function
DUsing 'init' hook instead of 'wp_enqueue_scripts'
Step-by-Step Solution
Solution:
  1. Step 1: Check the hook used for enqueuing scripts

    The 'init' hook is too early for enqueuing front-end scripts.
  2. Step 2: Identify the correct hook

    Scripts should be enqueued on 'wp_enqueue_scripts' hook for front-end.
  3. Final Answer:

    Using 'init' hook instead of 'wp_enqueue_scripts' -> Option D
  4. Quick Check:

    Correct hook is wp_enqueue_scripts [OK]
Quick Trick: Always enqueue scripts on wp_enqueue_scripts hook [OK]
Common Mistakes:
MISTAKES
  • Using 'init' hook for enqueuing
  • Forgetting to add the action hook
  • Incorrect function names

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes