从我的答案中复制粘贴,但添加了iframe/video mime类型:
Alter image output in content
function WPSE_80145_Mime($html, $id) {
//fetching attachment by post $id
$attachment = get_post($id);
$mime_type = $attachment->post_mime_type;
//get an valid array of video types, add any extra ones you need
$image_exts = array( \'video/mpeg\', \'video/mp4\', \'video/quicktime\' );
//checking the above mime-type
if (in_array($mime_type, $image_exts)) {
// the image link would be great
$src = wp_get_attachment_url( $id );
// enter you custom output here,
//you will want to change this to what you want in the iframe
$html = \'<iframe><a href="\' . $src . \'"></a></iframe>\';
return $html; // return new iframe wrapped video via $html
}
return $html;
}
add_filter(\'media_send_to_editor\', \'WPSE_80145_Mime\', 20, 2);