wordpress禁用REST API/移除wp-json链接的方法

来源:互联网 发布:国外优秀搜索引擎 知乎 编辑:程序博客网 时间:2024/05/20 00:09

WordPress 4.4更新新增了REST API功能,通过REST API可以很轻松的获取网站的数据,但是这个功能并不是每个网站都需要的,或者说我需要,但是并不希望他在head里面输出,所以给大家介绍下禁用REST API或者说移除head里面wp-json链接的方法。

禁用REST API

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里面输出的链接信息。

0 0
原创粉丝点击