久青草国产观看在线视频,在线观看欧美日女,777毛片,亚洲国产精品99久久久久久久

wordpress移除wp-json鏈接和wp-embed.min.js文件

2016-02-28 wordpress教程
  • 文章介紹
  • 快速入門
  • 評價&建議

最近更新了wordpress最新版本4.4,更新啥功能我也不知道,知道了我也用不上,但是發現代碼里面多出了好幾項功能鏈接,我也用不上。所以我們就把他移除掉,主要是多了REST API(通過REST API可以很輕松的獲取網站的數據)、wp-json鏈接、embeds功能(embeds功能可以允許更方便的引用第三方資源)、wp-embed.min.js文件。

用不上我們還加載它做什么,還影響網站的讀取速度,那么我們就來說說如何禁止掉。

先說說禁用REST API、移除wp-json鏈接的方法,將以下代碼添加到主題functions.php文件中即可禁用REST API并去除head里面輸出的鏈接信息:

  1. add_filter('rest_enabled',?'_return_false');
  2. add_filter('rest_jsonp_enabled',?'_return_false');
  3. remove_action(?'wp_head',?'rest_output_link_wp_head',?10?);
  4. remove_action(?'wp_head',?'wp_oembed_add_discovery_links',?10?);

禁用embeds其實還是比較復雜(代碼比較多),官方甚至為此開發了一個插件,大家可以使用插件來禁用:Disable Embeds,如果不想使用插件,那就將插件里面的代碼復制到主題的functions.php文件即可。

  1. function?disable_emojis()?{
  2. remove_action(?'wp_head',?'print_emoji_detection_script',?7?);
  3. remove_action(?'admin_print_scripts',?'print_emoji_detection_script'?);
  4. remove_action(?'wp_print_styles',?'print_emoji_styles'?);
  5. remove_action(?'admin_print_styles',?'print_emoji_styles'?);
  6. remove_filter(?'the_content_feed',?'wp_staticize_emoji'?);
  7. remove_filter(?'comment_text_rss',?'wp_staticize_emoji'?);
  8. remove_filter(?'wp_mail',?'wp_staticize_emoji_for_email'?);
  9. add_filter(?'tiny_mce_plugins',?'disable_emojis_tinymce'?);
  10. }
  11. add_action(?'init',?'disable_emojis'?);
  12. /**?
  13. *?Filter?function?used?to?remove?the?tinymce?emoji?plugin.?
  14. */
  15. function?disable_emojis_tinymce(?$plugins?)?{
  16. if?(?is_array(?$plugins?)?)?{
  17. return?array_diff(?$plugins,?array(?'wpemoji'?)?);
  18. }?else?{
  19. return?array();
  20. }
  21. }
  22. function?disable_embeds_init()?{
  23. global?$wp;
  24. $wp->public_query_vars?=?array_diff(?$wp->public_query_vars,?array(?'embed',?)?);
  25. remove_action(?'rest_api_init',?'wp_oembed_register_route'?);
  26. add_filter(?'embed_oembed_discover',?'__return_false'?);
  27. remove_filter(?'oembed_dataparse',?'wp_filter_oembed_result',?10?);
  28. remove_action(?'wp_head',?'wp_oembed_add_discovery_links'?);
  29. remove_action(?'wp_head',?'wp_oembed_add_host_js'?);
  30. add_filter(?'tiny_mce_plugins',?'disable_embeds_tiny_mce_plugin'?);
  31. add_filter(?'rewrite_rules_array',?'disable_embeds_rewrites'?);?}
  32. add_action(?'init',?'disable_embeds_init',?9999?);
  33. function?disable_embeds_tiny_mce_plugin(?$plugins?)?{?return?array_diff(?$plugins,?array(?'wpembed'?)?);?}
  34. function?disable_embeds_rewrites(?$rules?)?{?foreach?(?$rules?as?$rule?=>?$rewrite?)?{?if?(?false?!==?strpos(?$rewrite,?'embed=true'?)?)?{?unset(?$rules[?$rule?]?);?}?}
  35. return?$rules;?}
  36. function?disable_embeds_remove_rewrite_rules()?{?add_filter(?'rewrite_rules_array',?'disable_embeds_rewrites'?);?flush_rewrite_rules();?}
  37. register_activation_hook(?__FILE__,?'disable_embeds_remove_rewrite_rules'?);
  38. function?disable_embeds_flush_rewrite_rules()?{?remove_filter(?'rewrite_rules_array',?'disable_embeds_rewrites'?);?flush_rewrite_rules();?}
  39. register_deactivation_hook(?__FILE__,?'disable_embeds_flush_rewrite_rules'?);

每一次更新wordpress版本都會多出一些東西,例如之前的emoji,并且都在頁面上輸入內容,或多或少都會影響速度,我們博客基本就是更新下文章而已,搞的太負責了未免多此一舉,用不上就干掉REST API和embeds,為了用戶體驗,讓網站更快的展示我們碼的字就OK了。

0 0

企業建站推薦正版商業主題,國內專業團隊開發,完善售后,是您不二選擇。

正版主題商店

主題貓WP建站,累計幫助1300+客戶成功建站,為站長提供支持!

立刻開啟你的建站之旅
QQ在線客服

服務熱線

wordpress建站咨詢