W3cubDocs

/WordPress

rest_output_link_wp_head()

Outputs the REST API link tag into page header.

Description

See also

Source

function rest_output_link_wp_head() {
	$api_root = get_rest_url();

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

	printf( '<link rel="https://api.w.org/" href="%s" />', esc_url( $api_root ) );

	$resource = rest_get_queried_resource_route();

	if ( $resource ) {
		printf(
			'<link rel="alternate" title="%1$s" type="application/json" href="%2$s" />',
			_x( 'JSON', 'REST API resource link name' ),
			esc_url( rest_url( $resource ) )
		);
	}
}

Changelog

Version Description
4.4.0 Introduced.

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/rest_output_link_wp_head