Bird
0
0

What will be the output of this shortcode handler?

medium📝 component behavior Q5 of 15
Wordpress - Shortcodes and Blocks
What will be the output of this shortcode handler?
function welcome_shortcode($atts) {
  $atts = shortcode_atts(['user' => 'Visitor'], $atts);
  return "Welcome, " . $atts['user'] . "!";
}
// Usage: [welcome user="John"]
AWelcome, !
BWelcome, Visitor!
CWelcome, John!
DError: Undefined index 'user'
Step-by-Step Solution
Solution:
  1. Step 1: Understand shortcode_atts()

    This function merges user attributes with defaults.
  2. Step 2: Analyze usage

    The shortcode is used with user="John", so $atts['user'] is 'John'.
  3. Final Answer:

    Welcome, John! -> Option C
  4. Quick Check:

    Passed attribute overrides default [OK]
Quick Trick: Passed attributes override defaults [OK]
Common Mistakes:
  • Assuming default is always used
  • Expecting error without checking defaults
  • Ignoring shortcode_atts behavior

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes