rest_output_link_header

The timeline below displays how wordpress function rest_output_link_header has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Sends a Link header for the REST API.
 *
 * @since 4.4.0
 */
function rest_output_link_header()
{
    if (headers_sent()) {
        return;
    }
    $api_root = get_rest_url();
    if (empty($api_root)) {
        return;
    }
    header(sprintf('Link: <%s>; rel="https://api.w.org/"', sanitize_url($api_root)), false);
    $resource = rest_get_queried_resource_route();
    if ($resource) {
        header(sprintf('Link: <%s>; rel="alternate"; type="application/json"', sanitize_url(rest_url($resource))), false);
    }
}

WordPress Version: 5.5

/**
 * Sends a Link header for the REST API.
 *
 * @since 4.4.0
 */
function rest_output_link_header()
{
    if (headers_sent()) {
        return;
    }
    $api_root = get_rest_url();
    if (empty($api_root)) {
        return;
    }
    header(sprintf('Link: <%s>; rel="https://api.w.org/"', esc_url_raw($api_root)), false);
    $resource = rest_get_queried_resource_route();
    if ($resource) {
        header(sprintf('Link: <%s>; rel="alternate"; type="application/json"', esc_url_raw(rest_url($resource))), false);
    }
}

WordPress Version: 4.4

/**
 * Sends a Link header for the REST API.
 *
 * @since 4.4.0
 */
function rest_output_link_header()
{
    if (headers_sent()) {
        return;
    }
    $api_root = get_rest_url();
    if (empty($api_root)) {
        return;
    }
    header('Link: <' . esc_url_raw($api_root) . '>; rel="https://api.w.org/"', false);
}