Bird
0
0

Find the bug in this shortcode handler:

medium📝 Debug Q7 of 15
Wordpress - Shortcodes and Blocks
Find the bug in this shortcode handler:
function test_shortcode($atts) {
  $atts = shortcode_atts(['text' => 'Default'], $atts);
  echo $atts['text'];
}
add_shortcode('test', 'test_shortcode');
AFunction should return output, not echo
BMissing parameter in shortcode_atts
CShortcode name is invalid
DNo bug, code is correct
Step-by-Step Solution
Solution:
  1. Step 1: Understand shortcode handler output requirements

    Shortcode handlers must return output as string, not echo it.
  2. Step 2: Confirm other parts are correct

    shortcode_atts usage and shortcode registration are correct.
  3. Final Answer:

    Function should return output, not echo -> Option A
  4. Quick Check:

    Shortcode handlers must return output [OK]
Quick Trick: Return output string in shortcode functions, don't echo [OK]
Common Mistakes:
  • Using echo instead of return
  • Incorrect shortcode registration
  • Wrong parameter names in shortcode_atts

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes