Bird
0
0

Given this shortcode handler in PHP:

medium📝 component behavior Q13 of 15
Wordpress - Shortcodes and Blocks
Given this shortcode handler in PHP:
function greet_shortcode($atts) {
  $atts = shortcode_atts(['name' => 'Guest'], $atts);
  return "Hello, " . $atts['name'] . "!";
}

What will be the output of [greet name="Alice"] in a post?
AHello, Guest!
BHello, name!
CHello, Alice!
DHello, !
Step-by-Step Solution
Solution:
  1. Step 1: Understand shortcode_atts default and override

    The default name is 'Guest', but if 'name' is passed, it overrides the default.
  2. Step 2: Check the passed parameter

    The shortcode passes name="Alice", so $atts['name'] becomes 'Alice'.
  3. Final Answer:

    Hello, Alice! -> Option C
  4. Quick Check:

    Parameter overrides default value [OK]
Quick Trick: Passed parameters override defaults in shortcode_atts() [OK]
Common Mistakes:
  • Ignoring passed parameters and using defaults
  • Misreading the parameter key
  • Expecting output without parameter value

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes