宽度和高度为[1]
和[2]
. 因此,这些都添加在img标签上。如果主题具有html5 caption support 如果你有一个标题的话,这会输出扭曲的html(现在很标准)。
Corrected to check if there is a caption and return the WP shortcode or if no caption, then use the figure markup. Tested and works.
function html5_insert_image( $html, $id, $caption, $title, $align, $url, $size, $alt ) {
if( empty( $caption ) ) :
$src = wp_get_attachment_image_src( $id, $size, false );
$html = "<figure id=\\"post-$id media-$id\\" class=\\"align-$align\\">";
if ( $url ) {
$html .= "<a href=\\"$url\\" class=\\"image-link\\"><img src=\\"$src[0]\\" width=\\"$src[1]\\" height=\\"$src[2]\\" alt=\\"$alt\\" /></a>";
} else {
$html .= "<img src=\\"$src[0]\\" width=\\"$src[1]\\" height=\\"$src[2]\\" alt=\\"$alt\\" />";
}
$html .= "</figure>";
endif;
return $html;
}
add_filter( \'image_send_to_editor\', \'html5_insert_image\', 10, 9 );