Bird
0
0

Why does this child theme functions.php code cause a problem?

medium📝 Debug Q7 of 15
Wordpress - Theme Structure and Basics
Why does this child theme functions.php code cause a problem?
<?php
function enqueue_styles() {
  wp_enqueue_style('child-style', get_stylesheet_uri());
}
add_action('wp_enqueue_scripts', 'enqueue_styles');
wp_enqueue_style('parent-style', get_template_directory_uri() . '/style.css');
AFunction name conflicts with WordPress core
BMissing semicolon after function declaration
CUsing get_stylesheet_uri() instead of get_template_directory_uri()
DCalling wp_enqueue_style outside a function hooked to action runs too early
Step-by-Step Solution
Solution:
  1. Step 1: Identify where wp_enqueue_style is called

    It is called outside any function or hook, which runs too early.
  2. Step 2: Understand WordPress loading sequence

    Styles must be enqueued inside a function hooked to wp_enqueue_scripts action.
  3. Final Answer:

    Calling wp_enqueue_style outside a function hooked to action runs too early -> Option D
  4. Quick Check:

    Enqueue styles inside hooked function [OK]
Quick Trick: Always enqueue styles inside hooked functions [OK]
Common Mistakes:
MISTAKES
  • Calling enqueue functions directly in global scope
  • Confusing get_stylesheet_uri() with get_template_directory_uri()
  • Assuming function name causes conflict

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes