我用这个找到了解决方案How to change the markup Wordpress inserts for post images
我的最终代码是:
add_filter( \'image_send_to_editor\', \'add_custom_data_attribute_send_to_editor\', 10, 8 );
function add_custom_data_attribute_send_to_editor( $html, $id, $caption, $title, $align, $url, $size, $alt ){
if( $id > 0 ){
$post = get_post( $id );
$html = str_replace( "<img src", "<h2>$alt</h2><img src", $html );
}
return $html;
}