您可以使用oEmbed in Comments 插件。这是作者Evan Solomon在这个插件中使用的代码,我不久前在一个网站上使用过,只需将其复制到主题函数文件中,或者更好,下载他的插件:-)
class ES_oEmbed_Comments {
function __construct() {
add_action( \'init\', array( $this, \'init\' ) );
}
function init() {
if ( is_admin() )
return;
$this->add_filter();
}
/**
* Setup filter with correct priority to do oEmbed in comments
*/
function add_filter() {
// make_clickable breaks oEmbed regex, make sure we go earlier
$clickable = has_filter( \'get_comment_text\', \'make_clickable\' );
$priority = ( $clickable ) ? $clickable - 1 : 10;
add_filter( \'get_comment_text\', array( $this, \'oembed_filter\' ), $priority );
}
/**
* Safely add oEmbed media to a comment
*/
function oembed_filter( $comment_text ) {
global $wp_embed;
// Automatic discovery would be a security risk, safety first
add_filter( \'embed_oembed_discover\', \'__return_false\', 999 );
$comment_text = $wp_embed->autoembed( $comment_text );
// ...but don\'t break your posts if you use it
remove_filter( \'embed_oembed_discover\', \'__return_false\', 999 );
return $comment_text;
}
}
new ES_oEmbed_Comments;