問題描述
題
-
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 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。