由于v4.4 oEmbed特性被合并到core中。这允许用户只需粘贴URL即可在其网站上嵌入YouTube视频、推文和许多其他资源,WordPress会自动将URL转换为嵌入内容,并在可视化编辑器中提供实时预览。
Option 1
您可以通过将oembed功能添加到您的函数中来删除该功能。php
function disable_embeds_init() {
remove_shortcode( \'embed\' );
remove_filter( \'the_content\', [ $GLOBALS[\'wp_embed\'], \'autoembed\' ], 8 );
remove_filter( \'the_content\', [ $GLOBALS[\'wp_embed\'], \'run_shortcode\' ], 8 );
remove_action( \'edit_form_advanced\', [ $GLOBALS[\'wp_embed\'], \'maybe_run_ajax_cache\' ] );
}
add_action( \'init\', \'disable_embeds_init\', 9999 );
来源:
wp-includes/class-wp-embed.phpOption 2
或者,您可以使用
wp_dequeue_script
删除wp嵌入的函数:
function my_deregister_scripts(){
wp_dequeue_script( \'wp-embed\' );
}
add_action( \'wp_footer\', \'my_deregister_scripts\' );
Option 3
要完全删除oEmbed,可以使用以下代码:
function disable_embeds_code_init() {
remove_action( \'rest_api_init\', \'wp_oembed_register_route\' );
add_filter( \'embed_oembed_discover\', \'__return_false\' );
remove_filter( \'oembed_dataparse\', \'wp_filter_oembed_result\', 10 );
remove_action( \'wp_head\', \'wp_oembed_add_discovery_links\' );
remove_action( \'wp_head\', \'wp_oembed_add_host_js\' );
add_filter( \'tiny_mce_plugins\', \'disable_embeds_tiny_mce_plugin\' );
add_filter( \'rewrite_rules_array\', \'disable_embeds_rewrites\' );
remove_filter( \'pre_oembed_result\', \'wp_filter_pre_oembed_result\', 10 );
}
add_action( \'init\', \'disable_embeds_code_init\', 9999 );
function disable_embeds_tiny_mce_plugin($plugins) {
return array_diff($plugins, array(\'wpembed\'));
}
function disable_embeds_rewrites($rules) {
foreach($rules as $rule => $rewrite) {
if(false !== strpos($rewrite, \'embed=true\')) {
unset($rules[$rule]);
}
}
return $rules;
}
注:代码来源于
Disable Embeds 插件