Skip to content

Instantly share code, notes, and snippets.

@shawnkfinn
Created July 22, 2016 02:55
Show Gist options
  • Save shawnkfinn/1dcb33c66767c18043b97eeb9bccdbad to your computer and use it in GitHub Desktop.
Save shawnkfinn/1dcb33c66767c18043b97eeb9bccdbad to your computer and use it in GitHub Desktop.
Disable WordPress JSON/REST API and remove lines from source code / header
<?php // Copy and Paste snippet below into child-theme functions or custom plugin -- DELETE THIS LINE
// Disable WordPress JSON-REST API
function disable_json_api () {
// Remove the REST API lines from the HTML Header
remove_action( 'wp_head', 'rest_output_link_wp_head', 10 );
remove_action( 'wp_head', 'wp_oembed_add_discovery_links', 10 );
// Filters for WP-API version 1.x
add_filter('json_enabled', '__return_false');
add_filter('json_jsonp_enabled', '__return_false');
// Filters for WP-API version 2.x
add_filter('rest_enabled', '__return_false');
add_filter('rest_jsonp_enabled', '__return_false');
}
add_action( 'after_setup_theme', 'disable_json_api' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment