How to remove rest api link: in http headers?

i would like to remove the “link:” line added to the http headers since wordpress 4.4

here is a

curl -I killcandida.org

here is the output extract of the line that i would like to delete:
Link: <http://killcandida.org/wp-json/>; rel="https://api.w.org/"

Note that i don’t talk here about html headers but http headers.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

The output is generated by the rest_output_link_header(). This function is used in two actions, wp_head and template_redirect in default-filters.php:@line234. You can remove the function from those hooks to remove the output you wanted to remove. Put the following codes in your theme’s functions.php to achieve the desired result.

remove_action( 'wp_head', 'rest_output_link_wp_head', 10);    
remove_action( 'template_redirect', 'rest_output_link_header', 11);

Both actions are defined in ABSPATH/wp-includes/default-filters.php under // REST API filters.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments