Bird
0
0

What is wrong with this code?

medium📝 Debug Q7 of 15
Wordpress - Theme Structure and Basics
What is wrong with this code?
function load_my_styles() {
  wp_enqueue_style('my-style', get_template_directory() . '/style.css');
}
add_action('wp_enqueue_scripts', 'load_my_styles');
AUsing get_template_directory() instead of get_template_directory_uri()
BMissing the style handle
CWrong hook used
DNo error, code is correct
Step-by-Step Solution
Solution:
  1. Step 1: Understand the difference between directory and URI functions

    get_template_directory() returns a file path, not a URL.
  2. Step 2: Identify the correct function for URLs

    get_template_directory_uri() returns the URL needed for enqueuing styles.
  3. Final Answer:

    Using get_template_directory() instead of get_template_directory_uri() -> Option A
  4. Quick Check:

    Use get_template_directory_uri() for URLs [OK]
Quick Trick: Use get_template_directory_uri() for URLs, not get_template_directory() [OK]
Common Mistakes:
  • Using file path instead of URL
  • Confusing directory and URI functions
  • Forgetting to add action hook

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes