Skip to content

Instantly share code, notes, and snippets.

@timwhitlock
Created February 11, 2017 12:39
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save timwhitlock/ef62645c41ca61718fb2be7adcb641c6 to your computer and use it in GitHub Desktop.
Save timwhitlock/ef62645c41ca61718fb2be7adcb641c6 to your computer and use it in GitHub Desktop.
Disable WordPress REST API completely
<?php
/**
* Plugin Name: Disable REST API
* Version: 0
*/
// completely disable wp-json access
add_filter( 'rest_authentication_errors', function( $access ){
return new WP_Error( 'rest_cannot_access', 'Bye', array( 'status' => 403 ) );
} );
// also remove actions added by wp-includes/default-filters.php
remove_action( 'wp_head', 'rest_output_link_wp_head' );
remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );
remove_action( 'template_redirect', 'rest_output_link_header' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment