Hiding API routes list

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 Comment