Performance: Shortcodes with parameters
This affects page load speed and rendering by adding dynamic content processing during page generation.
[gallery ids="1,2,3" lazy="true"]
[gallery ids="1,2,3,4,5,6,7,8,9,10"]| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Shortcode with many parameters loading many items | High (many DOM nodes) | Multiple reflows due to large content | High paint cost due to images | [X] Bad |
| Shortcode with limited parameters and lazy loading | Low to medium DOM nodes | Single reflow after lazy load | Lower paint cost initially | [OK] Good |
color in WordPress PHP?function greet_shortcode($atts) {
$atts = shortcode_atts(['name' => 'Guest'], $atts);
return "Hello, " . $atts['name'] . "!";
}[greet name="Alice"] in a post?function example_shortcode($atts) {
return "Color is " . $atts['color'];
}[example color="red"][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>?Pass the test and this pattern moves unknown