Totally Disable WP API Feature

First make sure you don’t need any WP API feature for your Website. This snippet will disable your entire WP API feature. There are a lot of popular plugin which works via WP API. 

I’m showing you how you can disable WP API by copy paste a simple code inside your function.php file. If you think it’s complicated for you, you can do it via “WP Adminify” plugin too.

				
					// Disable ALL API

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', 11);
// 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');

// More REST API Hooks
remove_action('rest_api_init', 'wp_oembed_register_route'); // Remove the REST API endpoint.
remove_action('wp_head', 'wp_oembed_add_host_js'); // Remove oEmbed-specific JavaScript from the front-end and back-end.
add_filter('embed_oembed_discover', '__return_false'); // Turn off oEmbed auto discovery.
remove_filter('oembed_dataparse', 'wp_filter_oembed_result', 10); // Remove filter oEmbed results.
add_filter('rewrite_rules_array', 'adminify_disable_embeds_rewrites'); // Remove all embeds rewrite rules.

/**
* Remove all rewrite rules related to embeds.
* @param array $rules WordPress rewrite rules.
* @return array Rewrite rules without embeds rules.
*/
function adminify_disable_embeds_rewrites($rules)
{
    foreach ($rules as $rule => $rewrite) {
        if (false !== strpos($rewrite, 'embed=true')) {
            unset($rules[$rule]);
        }
    }

    return $rules;
}
				
			

You can find the function.php file inside you active theme’s root directory.

Disable all API using WP Adminify

After activating “WP Adminify” plugin inside your WordPress site, you will see a new option named “WP Adminify” inside your dashboard menu. Just click on this option and navigate to Tweak  > WP JSON API. Scroll down and you will see the “Totally Disable WP API Feature” option. Enable it and don’t forget to save your settings.

Totally Disable WP API Feature in WordPress website
Was this article helpful?

© 2021-2024 - Adminify | All rights reserved

WP Adminfy accepted payment methods