When you go to /wp-json or /wp-json/[namespace] on an API-enabled WordPress site, it shows all of the API routes and endpoints.

How can I disable this behaviour without disabling the REST API?

2 Answers
2

You can use the filter hook ‘rest_index’ :

add_filter('rest_index', function ($response) {
  $data = $response->get_data();

  $data['namespaces'] = [];
  $data['routes'] = [];

  return $data;
}, 9999, 1);

It is possible to remove your route from $data[‘namespaces’] and $data[‘routes’]

Leave a Reply

Your email address will not be published. Required fields are marked *