问题描述
题
-
wp-embed.min.js
文件是做什么的?我注意到它被添加到我的博客页脚尾。 -
我该如何摆脱呢?
功夫
经过一番搜索,我在食典中发现了 Embeds 。为什么 WordPress 想我默认添加视频等到我的页面?
环境
WordPress 4.4
最佳解决方案
我终于可以摆脱使用这个:
function my_deregister_scripts(){
wp_deregister_script( 'wp-embed' );
}
add_action( 'wp_footer', 'my_deregister_scripts' );
次佳解决方案
Trix 的答案并不适用于 WordPress 4.4.1
,但我在 Disable Embeds WordPress 插件的代码中找到了一个解决方案。在主题的 functions.php
文件中添加此代码 (已修改),以从前端完全删除 wp-embed.min.js
文件:
add_action( 'init', function() {
// Remove the REST API endpoint.
remove_action('rest_api_init', 'wp_oembed_register_route');
// Turn off oEmbed auto discovery.
// Don't filter oEmbed results.
remove_filter('oembed_dataparse', 'wp_filter_oembed_result', 10);
// Remove oEmbed discovery links.
remove_action('wp_head', 'wp_oembed_add_discovery_links');
// Remove oEmbed-specific JavaScript from the front-end and back-end.
remove_action('wp_head', 'wp_oembed_add_host_js');
}, PHP_INT_MAX - 1 );
第三种解决方案
我认为这部分还是缺少。
What does the wp-embed.min.js file do? I noticed it is added to the end of my blog page footer.
这个问题的答案是正确的。 https://core.trac.wordpress.org/changeset/35708
Embeds: Remove & characters from the inline embed JS.
Older versions of WordPress will convert those & characters to &, which makes for some non-functional JS. If folks are running an older release, let’s not make their lives more difficult than it already is.
它还将尝试嗅探用户代理。
参考文献
注:本文内容整合自 Google/Baidu/Bing 辅助翻译的英文资料结果。如果您对结果不满意,可以加入我们改善翻译效果:薇晓朵技术论坛。