MainWP Community

Disable WP Rest API

Use this code snippet to disable the WP REST API on your child sites.

Snippet Type

Execute on Child Sites

Snippet

add_filter('rest_enabled', '__return_false');
remove_action( 'init', 'rest_api_init' );
remove_action( 'rest_api_init', 'rest_api_default_filters', 10, 1 );
remove_action( 'parse_request', 'rest_api_loaded' );
remove_action( 'rest_api_init', 'wp_oembed_register_route');
remove_filter( 'rest_pre_serve_request', '_oembed_rest_pre_serve_request', 10, 4 );
remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );

Is this a must? What is the purpose behind?

@naxiand it’s not a must, some people turn it off for security reasons.

2 Likes

Customers using say WooCommerce REST API keys for services that need it then you would not want to disable the WordPress REST API.

2 Likes