Bird
0
0

You added this code to functions.php but it causes a fatal error:

medium📝 Debug Q6 of 15
Wordpress - Theme Structure and Basics
You added this code to functions.php but it causes a fatal error:
function greet_user() {
  echo 'Hello!';
}
add_action('init', greet_user);
What is the cause of the error?
AThe <code>add_action</code> call is missing a priority parameter.
BThe <code>init</code> hook cannot be used in <code>functions.php</code>.
CThe function should return a value instead of echoing.
DThe function name is not quoted in the <code>add_action</code> call.
Step-by-Step Solution
Solution:
  1. Step 1: Check the add_action syntax

    The second parameter must be a string with the function name, but here it is unquoted.
  2. Step 2: Understand PHP function references

    Without quotes, PHP treats greet_user as a constant, causing a fatal error.
  3. Final Answer:

    The function name is not quoted in the add_action call. -> Option D
  4. Quick Check:

    Function names in add_action must be strings [OK]
Quick Trick: Function names in add_action need quotes [OK]
Common Mistakes:
  • Omitting quotes around function names
  • Assuming hooks can't be used in functions.php
  • Thinking echo causes fatal errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes