How to Disable JSON REST API in WordPress?

Are you looking for a way to disable JSON REST API in WordPress?

WordPress introduced JSON REST API with the release of WordPress version 4.4. It was a great addition for WordPress plugin developers. Many site owners may not find it useful at all and may want to disable JSON Rest API in WordPress to keep their website secure.

Keeping the JSON Rest API in WordPress enabled opens your website to DDoS attacks. It also slows down your WordPress website as it consumes server resources.

Therefore, as a WordPress site administrator, it’s ideal to disable WordPress REST API in WordPress. Use the following code to achieve that.

php
/**
 * Disable WordPress REST API
 */
function maverick_wordpress_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', 'maverick_wordpress_disable_rest_api');

Leave a Reply

Your email address will not be published. Required fields are marked *