您将分别返回每一行。它只会输出第一行return 停止函数的执行。相反,通过连接将每一行添加到字符串中.=:
function wpse_276152_image_shortcode( $atts ) {
$atts = shortcode_atts( array(
\'to\' => \'https://pics.wikifeet.com/Melania-Trump-Feet-720891.jpg\'
), $atts );
$output = \'<div class="class1">\';
$output .= \'<img class="class2" src="\' . $atts[\'to\'] . \'" alt="The First Caption" width="100%" height="auto">\';
$output .= \'<i class="fa fa-expand" aria-hidden="true"></i>\';
$output .= \'</div>\';
return $output;
}
add_shortcode( \'the_image\', \'wpse_276152_image_shortcode\' );
.= 就是说
$output = $output . \' string to add\'.
还请注意我所做的其他一些更改:
the_image 对于函数而言,名称过于泛型。你越来越容易遇到冲突问题。请注意,函数名和短代码不需要相同请勿使用extract(). 随着代码变得越来越复杂make maintenance needlessly difficult.