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?
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?
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’]