如何隐藏 wp-json

wordoress 默认会在两个地方出现 wp-json 。一个是 html 中的 header 部分。 一个 http 协议的相应标头中。

Connection: keep-alive
Content-Encoding: gzip
Content-Type: text/html; charset=UTF-8
Date: Mon, 16 Feb 2022 02:39:17 GMT
Link: <https://www.wpcode.cn/wp-json/>; rel="https://api.w.org/"
Server: nginx
Strict-Transport-Security: max-age=31536000; includeSubDomains
Transfer-Encoding: chunked
X-Powered-By: PHP/7.4.1

删除 wp-json

// 移除 header 中的 
remove_action('wp_head', 'rest_output_link_wp_head', 10 );
// 移除 http 消息头中的
remove_action('template_redirect', 'rest_output_link_header', 11 );