Bird
0
0

This code snippet is added to functions.php but causes a fatal error:

medium📝 Debug Q14 of 15
Wordpress - Theme Structure and Basics
This code snippet is added to functions.php but causes a fatal error:
function my_custom_function() {
  echo 'Welcome!'
}
add_action('wp_head', 'my_custom_function');
What is the error and how to fix it?
AMissing semicolon after echo statement; add ; after 'Welcome!'
BWrong hook name; change 'wp_head' to 'wp_footer'
CFunction name is invalid; rename function
DEcho cannot be used in functions.php; use return instead
Step-by-Step Solution
Solution:
  1. Step 1: Identify syntax error in PHP code

    The echo statement lacks a semicolon at the end of the line, which causes a fatal syntax error.
  2. Step 2: Correct the syntax

    Adding a semicolon after 'Welcome!' fixes the error: echo 'Welcome!';
  3. Final Answer:

    Missing semicolon after echo statement; add ; after 'Welcome!' -> Option A
  4. Quick Check:

    PHP statements need semicolons [OK]
Quick Trick: Check for missing semicolons after PHP statements [OK]
Common Mistakes:
  • Ignoring missing semicolon errors
  • Changing hook unnecessarily
  • Thinking echo is disallowed in functions.php

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes