唯一可靠的跨浏览器解决方案是嵌入。pdf格式iframe
.
add_filter(\'media_send_to_editor\', \'my_pdf_embed\', 20, 3);
function my_pdf_embed($html, $id) {
$attachment = get_post($id); //fetching attachment by $id passed through
$mime_type = $attachment->post_mime_type; //getting the mime-type
if ($mime_type == \'application/pdf\') { //checking mime-type
$src = wp_get_attachment_url( $id );
//change the size to your liking
$html = \'<iframe width="500" height="500" src="\'.$src.\'"></iframe>\';
return $html; // return new $html
}
return $html;
}