WordPress Disabled REST API

WordPress says that you should not disable the REST API because it will break future functionality that will use API actively. But however you can filter the access from external by doing the code below :

edit functions.php at active theme’s folder and add the code below :


// REMOVE REST API INFO FROM HEADER
remove_action('xmlrpc_rsd_apis', 'rest_output_rsd' );
remove_action('wp_head', 'rest_output_link_wp_head', 10 );
remove_action('wp_head', 'wp_oembed_add_discovery_links', 10);
remove_action('template_redirect', 'rest_output_link_header', 11 );

/* DISABLE WP REST API */
add_filter( 'rest_authentication_errors', function( $result ) {
    wp_die( __( 'Sorry REST API currently disabled, please visit the homepage' ) );
});

Leave a Reply

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