WPSurfer.com

How to Disable Rest API and Rest API Links

Published on September 24, 2022 | Updated on September 24, 2022

The WordPress REST API allows developers to build applications that interact with WordPress, accessing data and functionalities programmatically.

However, there are cases where site administrators may want to disable the REST API for security, performance, or privacy reasons.

Here’s the code snippet we’ll use to disable the REST API:

add_filter(
	'rest_authentication_errors',
	function ( $access ) {
		return new WP_Error(
			'rest_disabled',
			__( 'The WordPress REST API has been disabled.' ),
			array(
				'status' => rest_authorization_required_code(),
			)
		);
	}
);
Manuel Campos

Manuel Campos

I am José Manuel. I am writing about things I know and things that I am learning about WordPress. I hope you find the content of this blog useful.