WordPress at a glance
Home All Function Functions APIs REST API

rest_output_link_wp_head() WP 4.4.0

Displays a link to the root REST API route in the <head> section on all site pages.

The link looks like:

<link rel='https://api.w.org/' href='http://wp-test.ru/wp-json/' />

This link is a notification to client applications that the current site has its own API.

By default, this function is called via wp_head hook

add_action( 'wp_head', 'rest_output_link_wp_head', 10, 0 );

A similar link is added to the server response headers by the rest_output_link_header() function that by default is called on the following hook:

add_action( 'template_redirect', 'rest_output_link_header', 11, 0 );
Works based on: get_rest_url()
✈ 1 time = 0.004168s = very slow | 50000 times = 4.19s = fast | PHP 7.1.11, WP 4.9.8

No Hooks.

Return

Null. Nothing.

Usage

rest_output_link_wp_head();

Examples

#1 Remove the REST API link

The below code does not disable the REST API but only cancels the link output on all pages of the site. This code can be inserted into a plugin or theme's functions.php file.

remove_action( 'wp_head', 'rest_output_link_wp_head' );

Notes

  • See: get_rest_url()

Changelog

Since 4.4.0 Introduced.

Code of rest output link wp head: wp-includes/rest-api.php WP 5.2.4

<?php
function rest_output_link_wp_head() {
	$api_root = get_rest_url();

	if ( empty( $api_root ) ) {
		return;
	}

	echo "<link rel='https://api.w.org/' href='" . esc_url( $api_root ) . "' />\n";
}

Related Functions

From tag: REST API

No comments
    Hello, !     Log In . Register