Remove api.w.org REST API from WordPress header

Wordpress API JSONWordPress uses the REST API since version 4.4 of the CMS. It enables developers to connect with the WordPress back-end more easily, since this API is a standardised way to connect. However, this also adds the following header to your Worpress website:

<link rel='https://api.w.org/' href='https://thomas.vanhoutte.be/miniblog/wp-json/' />

To remove this added header from WordPress, you can edit your functions.php file within your theme’s directory.

function remove_api () {
remove_action( 'wp_head', 'rest_output_link_wp_head', 10 );
remove_action( 'wp_head', 'wp_oembed_add_discovery_links', 10 );
}
add_action( 'after_setup_theme', 'remove_api' );

Once you add this function to the functions.php file of your WordPress installation, refresh your website and the attribute is no longer shown in the <head></head> of the HTML file generated by WP.

Note that the REST API functionality will still be working as it used to; this only removes the header code that is being inserted.

 

Author Bio

Thank you for your interest in my blog! On this miniblog, I write mostly short (technical) blog posts that might interest other people. Read more about me or feel free to contact me.

 

6 thoughts on “Remove api.w.org REST API from WordPress header

  1. // Disable REST API
    remove_action( ‘template_redirect’, ‘rest_output_link_header’, 11, 0 );
    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’);

  2. Is the add_action function really needed? Most of the suggestions I see for removing meta data link from WP’s header don’t include it.

  3. Hi, Where exactly in the functions.php do we add these codes. Please give complete guidance for newbies or non-programmers. I wait for your reply. Thanks. Suresh

    1. Suresh you should make a child theme (I use the manager From Lilea), activate that, copy functions.php, then edit that to add. If you edit original theme it will be lost in updates. It doesn’t matter where you add it, I just go to the end.

Leave a Reply

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