Bird
0
0

What will be the output when the following code runs in a WordPress theme?

medium📝 component behavior Q13 of 15
Wordpress - WordPress Hooks System
What will be the output when the following code runs in a WordPress theme?
add_action('wp_head', function() { echo '<!-- Header comment -->'; });
AThe code will cause a fatal error due to incorrect hook usage.
BThe comment <!-- Header comment --> will appear inside the HTML <head> section.
CThe comment will not appear because anonymous functions are not allowed.
DThe comment will appear at the bottom of the page before </body>.
Step-by-Step Solution
Solution:
  1. Step 1: Understand the wp_head hook timing

    The wp_head hook runs inside the HTML <head> section of the page.
  2. Step 2: Analyze the anonymous function output

    The function echoes an HTML comment, so it will be output exactly where the hook runs, inside <head>.
  3. Final Answer:

    The comment <!-- Header comment --> will appear inside the HTML <head> section. -> Option B
  4. Quick Check:

    wp_head outputs inside <head> [OK]
Quick Trick: Remember wp_head outputs inside <head> tag [OK]
Common Mistakes:
  • Thinking output appears in footer
  • Believing anonymous functions are disallowed
  • Assuming hook causes error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes