How to Disable the JSON REST API in WordPress


First, you will need to connect to your server using your FTP credentials and navigate to the root WordPress directory, often called public_html.

Then, navigate to the /wp-content/themes directory and click on the directory of your currently active theme to open it. Locate the functions.php and add the following code:

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

After that, check whether everything works as it should by examining one of the JSON REST API routes that are present on your website.


About Author

Comments are closed.