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里面輸出的鏈接信息。
以上就是本文章的內容,希望對大家有所幫助
新聞熱點
疑難解答