您的代码是正确的,只需更改$atts变量。
// if you want to add image, alt attribute on shortcode statically
$atts = shortcode_atts(
array(
\'image_src\' => \'\',
\'alt\' => \'\',
\'add_img_class\' => \'\',
\'id\' => \'\'
), $atts, \'hero-banner\'
);
// if you pass image and alt attribute dynamically
$atts = shortcode_atts(
array(
\'image_src\' => \'dynamic data\',
\'alt\' => \'dynamic data\',
\'add_img_class\' => \'\',
\'id\' => \'\'
), $atts, \'hero-banner\'
);
当我们使用带有关闭动态参数的内容时,会用到它。请查找以下示例
function wrap_content_shortcode_callback($atts, $content, $tag){
$output = \'<span style="font-size: 120%;">\' . $content . \'</span>\';
return $output;
}
add_shortcode(\'wrap_shortcode\',\'wrap_content_shortcode_callback\');
//use shortcode like this: [wrap_shortcode]test123[/wrap_shortcode]