我正在尝试从我的一些 WordPress 输出中删除 YouTube 嵌入,因此它只显示链接。
我已经尝试了以下代码,但没有任何运气。
wp_oembed_remove_provider('#http://(www\.)?youtube\.com/watch.*#i');
wp_oembed_remove_provider('#https://(www\.)?youtube\.com/watch.*#i');
wp_oembed_remove_provider('#http://youtu\.be/.*#i');
wp_oembed_remove_provider('#https://youtu\.be/.*#i');
echo apply_filters("the_content", $result->text);
我究竟做错了什么?我如何正确地做到这一点?
最佳答案
您可能处于删除提供程序为时已晚的地步。尝试连接到 plugins_loaded
或 init
:
add_action( 'init', 'so26743803_wp_oembed_remove_provider' );
function so26743803_wp_oembed_remove_provider(){
wp_oembed_remove_provider('#https://youtu\.be/.*#i');
// etc.
}
编辑(未经测试):使用
oembed_providers
取消设置提供程序过滤器(见 this Q):add_filter( 'oembed_providers', 'so26743803_oembed_providers' );
function so26743803_oembed_providers( $providers )
{
unset( $providers['#http://youtu\.be/.*#i'] );
// etc.
return $providers;
}
关于wordpress - 使用 wp_oembed_remove_provider() 删除 YouTube 嵌入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26743803/