wordpress禁用REST API/移除wp-json链接的方法
-->
WordPress 4.4更新新增了REST API功能,通过REST API可以很轻松的获取网站的数据,但是这个功能并不是每个网站都需要的,或者说我需要,但是并不希望他在head里面输出,所以给大家介绍下禁用REST API或者说移除head里面wp-json链接的方法。
禁用REST API
1 2 3 4 5 6 7 8 9 10 | add_filter('rest_enabled', '_return_false'); add_filter('rest_jsonp_enabled', '_return_false'); remove_action( 'wp_head', 'rest_output_link_wp_head', 10 ); remove_action( 'wp_head', 'wp_oembed_add_discovery_links', 10 ); add_filter('rest_enabled', '_return_false'); add_filter('rest_jsonp_enabled', '_return_false'); remove_action( 'wp_head', 'rest_output_link_wp_head', 10 ); remove_action( 'wp_head', 'wp_oembed_add_discovery_links', 10 ); |
将以上代码添加到主题functions.php文件中即可禁用REST API并去除head里面输出的链接信息。
wordpress禁用REST API/移除wp-json链接的方法