WordPress 技巧:屏蔽 REST API

WordPress 完全禁用 REST API(最新版)

WordPress 4.4 的 REST API 很 cool,但是很多用户还是想安静写写博客,那么你可以在当前主题的 functions 文件中添加入下代码屏蔽 REST API:

// 屏蔽 REST API
add_filter('json_enabled', '__return_false' );
add_filter('json_jsonp_enabled', '__return_false' );
add_filter('rest_enabled', '__return_false');
add_filter('rest_jsonp_enabled', '__return_false');

// 移除头部 wp-json 标签<link rel="https://api.w.org/" href="https://pdbn.top/wp-json/"> 
remove_action('wp_head', 'rest_output_link_wp_head', 10 ); 
//移除HTTP header 中的Link: <https://pdbn.top/wp-json/>; rel="https://api.w.org/"
remove_action('template_redirect', 'rest_output_link_header', 11 );

另外需要注意的是,屏蔽 REST API 会直接导致 文章 Embed 功能失效

摘自http://blog.wpjam.com/m/wordpress-post-embed/