Bird
0
0

What will be the output of this code snippet when the current post does NOT have a featured image?

medium📝 Predict Output Q4 of 15
Wordpress - Content Management
What will be the output of this code snippet when the current post does NOT have a featured image?
if (has_post_thumbnail()) {
  the_post_thumbnail('large');
} else {
  echo 'Image missing';
}
ADisplays the featured image in 'large' size
BDisplays a default WordPress image
CThrows a PHP error
DOutputs 'Image missing'
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate has_post_thumbnail()

    This function returns false if no featured image is set for the current post.
  2. Step 2: Execute else block

    Since the condition is false, the else block runs, outputting 'Image missing'.
  3. Final Answer:

    Outputs 'Image missing' -> Option D
  4. Quick Check:

    Check if post has thumbnail; if not, else runs [OK]
Quick Trick: has_post_thumbnail() false triggers else block [OK]
Common Mistakes:
  • Assuming the_post_thumbnail() outputs a default image automatically
  • Confusing has_post_thumbnail with a property instead of a function
  • Expecting no output if no featured image is set

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes