Disable WP Rest API V2

By | May 31, 2017

Disable WordPress WP REST API V2.

WordPress WP REST API V2 give many advantages for website developers to make an interaction in a wordpress website. It can be used to create, fetch, edit and also delete posts , taxonomies and also retrieve another information from a website in JSON format.

But not all of website’s owners need or love this function. By some reasons some website’s owner or web developers want to disable this function. Some of that reason are :

  1. Security
    In version 4.7 and 4.7.1 of wordpress there is Content Injection Vulnerability you can read more details in sucuri blog.
  2. Protect Content.
    With WP-JSON Api someone can viewing posts data in JSON format. It will makes a website’s scrapper more easily to scrape a wordpress websites’s content. It will not 100% protected your website’s content but it will be a bit harder to a scrapper to grab your content.

Disable Rest API V2 With Plugin

Now if you want to disable wp json api for your blog you can do it by installing Disable REST API Plugin.

** As of WordPress 4.7, the filter provided for disabling the REST API has been removed. However, this plugin will now
forcibly return an authentication error to any API requests from sources who are not logged into your website, which
will effectively still prevent unauthorized requests from using the REST API to get information from your website **

You can download it here : https://wordpress.org/plugins/disable-json-api/ or directly from your wordpress dashboard.

Disable Rest API V2 Without Plugin

If you do not want to use a plugin , in your theme function. (function.php) add this following code.

add_filter( 'rest_authentication_errors', function( $result ) {
if ( ! empty( $result ) ) {
    return $result;
if ( ! is_user_logged_in() ) {
    return new WP_Error( 'restx_logged_out', 'Sorry, you must be logged in to make a request.', array( 'status' => 401 ) );
return $result;

Related Posts


WP REST API Create Post with jQuery Ajax

Wordpress WP REST API v2 tutorial create post with jquery ajax using basic authentication with code example

Change Search Permalink WordPress

How to change search slug permalink wordpress with any words you want


Autocomplete WordPress Search Form With WP REST API

WordPress Tutorial Create Autocomplete Search Form Using WP REST API V2 With Code Example


WP REST API Upload Image Media

Wordpress WP REST API V2 tutorial and code example upload image / media with PHP cURL

wp rest api v2

WP REST API Get Featured Image With Custom Endpoint

WP REST API Get Featured Image By Adding Custom Endpoint in Theme Function