問題描述

  1. wp-embed.min.js 檔案是做什麼的?我注意到它被新增到我的部落格頁尾尾。

  2. 我該如何擺脫呢?

功夫

經過一番搜尋,我在食典中發現了 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 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。