Use code PERFMATTERS for an additional 10% off! ūüí•

How to Remove WordPress REST API Links

The WordPress REST API enables the CMS to communicate with other web properties, no matter what programming language they’re written in. According to the WordPress handbook:

The WordPress REST API provides API endpoints for WordPress data types that allow developers to interact with sites remotely by sending and receiving JSON (JavaScript Object Notation) objects.

However, a lot of sites don’t use this, and therefore in most cases, it is just unnecessary code. By default, every site includes a link in the header:

<link rel='https://api.w.org/' href='https://domain.com/wp-json/' />

There is also a header that is sent on each request:

function rest_output_link_header() {
 if ( headers_sent() ) {
 return;
 }
 
 $api_root = get_rest_url();
 
 if ( empty( $api_root ) ) {
 return;
 }

There is also an API tag that gets added to the Really Simple Discovery (RSD) endpoint.

<api name="WP-API" blogID="1" preferred="false" apiLink="<?php echo esc_url( $api_root ); ?>" />

You can easily remove WordPress REST API links by enabling the ‚ÄúRemove REST API Links‚ÄĚ option.

Remove WordPress REST API links in header
Remove WordPress REST API links in header

The above only removes the front-end code. Check out our article on how to completely disable the WordPress REST API.

Was this article helpful?

Related Articles