Bird
0
0

What is the issue with this shortcode handler?

medium📝 Debug Q6 of 15
Wordpress - Shortcodes and Blocks
What is the issue with this shortcode handler?
function display_shortcode($atts) {
  return "Number: " . $atts['number'];
}
add_shortcode('display', 'display_shortcode');

Used as: [display]
AShortcode name 'display' is invalid
BShortcode is missing the add_shortcode call
CFunction should echo instead of return
DAccessing undefined index 'number' without default causes a PHP notice
Step-by-Step Solution
Solution:
  1. Step 1: Check parameter usage

    The handler accesses $atts['number'] without setting a default.
  2. Step 2: Analyze shortcode usage

    Since [display] is used without parameters, 'number' is undefined.
  3. Final Answer:

    Accessing undefined index 'number' without default causes a PHP notice -> Option D
  4. Quick Check:

    Always set defaults to avoid notices [OK]
Quick Trick: Always provide defaults for shortcode parameters [OK]
Common Mistakes:
  • Ignoring missing defaults
  • Expecting echo instead of return
  • Assuming shortcode registration is missing

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes