Bird
0
0

This code in functions.php causes a blank page error:

medium📝 Debug Q7 of 15
Wordpress - Theme Structure and Basics
This code in functions.php causes a blank page error:
add_action('wp_head', 'print_message');
function print_message() {
  echo 'Hi there!';
  exit;
}
What is the problem?
AFunction name must be declared before add_action
BEcho cannot be used in wp_head hook
CCalling exit stops page loading, causing blank page
Dwp_head hook does not allow custom functions
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the function behavior

    The function echoes a message then calls exit, which stops PHP execution immediately.
  2. Step 2: Understand impact on page rendering

    Calling exit in wp_head prevents the rest of the page from loading, resulting in a blank page.
  3. Final Answer:

    Calling exit stops page loading, causing blank page -> Option C
  4. Quick Check:

    exit halts PHP, causing blank page [OK]
Quick Trick: Avoid exit in hooks to prevent blank pages [OK]
Common Mistakes:
  • Using exit inside hooked functions
  • Thinking echo is disallowed in wp_head

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes