Bird
0
0

Which PHP function correctly handles both parameters with defaults and returns a string like <div class='box large' style='background:green;'>Box</div>?

hard📝 state output Q15 of 15
Wordpress - Shortcodes and Blocks
You want to create a shortcode [box color="green" size="large"] that outputs a colored box with size text. Which PHP function correctly handles both parameters with defaults and returns a string like <div class='box large' style='background:green;'>Box</div>?
Afunction box_shortcode($atts) { $atts = shortcode_atts(['color' => 'blue', 'size' => 'medium'], $atts); return "
Box
"; }
Bfunction box_shortcode($color, $size) { return "
Box
"; }
Cfunction box_shortcode() { return "
Box
"; }
Dfunction box_shortcode($atts) { return "
Box
"; }
Step-by-Step Solution
Solution:
  1. Step 1: Use shortcode_atts() to set defaults for 'color' and 'size'

    function box_shortcode($atts) { $atts = shortcode_atts(['color' => 'blue', 'size' => 'medium'], $atts); return "
    Box
    "; } correctly merges defaults with passed parameters safely.
  2. Step 2: Return properly formatted HTML string with parameters

    function box_shortcode($atts) { $atts = shortcode_atts(['color' => 'blue', 'size' => 'medium'], $atts); return "
    Box
    "; } uses correct string interpolation to build the div with class and style attributes.
  3. Final Answer:

    function box_shortcode($atts) { $atts = shortcode_atts(['color' => 'blue', 'size' => 'medium'], $atts); return "
    Box
    "; }
    -> Option A
  4. Quick Check:

    Use shortcode_atts() and interpolate parameters in output [OK]
Quick Trick: Use shortcode_atts() and string interpolation for parameters [OK]
Common Mistakes:
  • Not using shortcode_atts() for defaults
  • Wrong function parameters
  • Incorrect string concatenation or quotes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes