Use code PERFMATTERS for an extra 10% off!
  1. Home
  2. Docs
  3. General
  4. How to remove WordPress REST API links

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 ); ?>" />

Remove WordPress REST API links

Follow the steps below to remove REST API links.

Step 1

Click into the Perfmatters plugin settings.

Perfmatters plugin settings
Perfmatters plugin settings

Step 2

Make sure you’re on the “General” submenu.

Perfmatters General submenu
Perfmatters General submenu

Step 3

Scroll down and toggle on “Remove REST API Links.”

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

Step 4

Scroll down and click “Save Changes.”

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