0

Without the use of plugin how is possible to deactivate wp-json and redirect the URL to a 404 page. Whenever someone calls example.com/wp-json it redirects it to 404 page instead of loading?

I tried to do it via htaccess but it's not working any possible solution please?

0

2 Answers 2

0

Does adding this to functions.php work ?

add_filter('json_enabled', '__return_false');
add_filter('json_jsonp_enabled', '__return_false');
1
  • I don't see either of those in the latest 6.4 code. There is a rest_jsonp_enabled but it wouldn't turn on the REST API on its own, and rest_enabled has been deprecated in favour of using rest_authentication_errors (yuck)
    – Rup
    Commented Mar 11 at 16:35
0

Add the this snippet to your wp-includes/functions.php file

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

from wpdynamic.com

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.